I was going through the explanation for Rod Cutting Problem on geeksforgeeks and there this code was mention to solve Rod Cutting Problem but i am weak in recursion and don't know anything about DP. So Please can anyone help me out please..!! Problem Statement: Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. Determine the maximum value obtainable by cutting up the rod and selling the pieces. And here is the code:
Resource Link: http://www.geeksforgeeks.org/dynamicprogrammingset13cuttingarod/ Help Please..!! asked 26 Dec '14, 21:42

Lets try to understand the solution using a simple example.Let's say the given distribution of money for lengths are as: Let's consider L=4 for the first sub case. Since our condition does not match the base condition we enter the for loop.
Since we passed n=4, our loop will run 4 times from i=0 to i=3.
max_val=max(max_val,price[0]+cutRod(price,3(401));
Now we compare!
Here is a visual representation. In case the image doesn't fit in,here is a direct link (http://discuss.codechef.com/upfiles/Screenshot_16.png) Hope it helps now :). Sorry if I went wrong anywhere,feel free to correct me. My first explanation attempt ever.Cheers :D EDIT : Note that the term "1+" only describes the first call i.e i=0,not a generalization as price[i] may vary. answered 26 Dec '14, 22:40

Here cutRod(int price[],int n) returns maximum amount obtained by cutting up the rod and selling the pieces. Now you considered all possibilities answered 26 Dec '14, 22:29

@h1ashdr@gon what happens after cutrod(p,0) returns 0??i understand why cutrod(p,0) returns 0 but what will happen after that?? answered 19 Apr '15, 03:00
