Mid Coding

Rod Cutting Problem?

int RodCutting(int[] prices, int n)

int[] dp = new int[n + 1];

dp[0] = 0;

Follow on:

for (int i = 1; i <= n; i++)

int maxVal = int.MinValue;

for (int j = 0; j < i; j++)

maxVal = Math.Max(maxVal, prices[j] + dp[i - j - 1]);

dp[i] = maxVal;

return dp[n];

Explanation:

Max revenue by cutting rod into pieces of various lengths.

More from C# Programming Tutorial

All questions for this course