diff --git a/algorithms/CPlusPlus/Dynamic-Programming/stickler-thief.cpp b/algorithms/CPlusPlus/Dynamic-Programming/stickler-thief.cpp new file mode 100644 index 00000000..11c7f29d --- /dev/null +++ b/algorithms/CPlusPlus/Dynamic-Programming/stickler-thief.cpp @@ -0,0 +1,31 @@ +// Given an Array which represents a linear arrangement of houses on a street ,The Integers represent the amount of money in every house. +// A Thief is planning on robbing the entire street but he can only loot houses that are not adjacent. +// Find the maximum amount of money that can be looted from the street. + +#include +using namespace std; +int loot(int arr[],int n){ + if(n==1) return arr[0]; + int dp[n]; //DP table to keep track of maximum amount lootable until a point + dp[0]=arr[0];//Base case 1: at 0th index the only way to choose houses is the one house available + dp[1]=max(arr[0],arr[1]); //Base case 2: at 1st index you can either choose the first or the second house out of the two houses + + for(int i=2;i>n; + int arr[n]; + cout<<"Input the amount of loot for every house"<>arr[i]; + } + cout<<"The maximum possible loot"<