Skip to content

Instantly share code, notes, and snippets.

@bkb181
Created July 10, 2020 11:18
Show Gist options
  • Save bkb181/1c5fe6de6659bd255f71d4f36d428012 to your computer and use it in GitHub Desktop.
Save bkb181/1c5fe6de6659bd255f71d4f36d428012 to your computer and use it in GitHub Desktop.
int rod_cut(int price[], int n)
{
int T[n+1], i, j;
for (int i = 0; i <= n; i++)
T[i] = 0;
for(i= 1; i<= n; i++)
{
for(j= 1; j<= i; j++)
T[i]= max(T[i], price[j-1] + T[i - j]);
}
return T[n];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment