From 1d8fbaaa47a7b46dc2d0bf07090ed647862f148d Mon Sep 17 00:00:00 2001 From: the-void-century <46325253+the-void-century@users.noreply.github.com> Date: Mon, 11 Jul 2022 19:14:27 +0530 Subject: [PATCH] Create stickler-thief.cpp // 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. --- .../Dynamic-Programming/stickler-thief.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 algorithms/CPlusPlus/Dynamic-Programming/stickler-thief.cpp 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"<