From 233a88078e27774864dfeba600ab8629a445d35c Mon Sep 17 00:00:00 2001 From: pkdism Date: Thu, 1 Dec 2016 19:44:32 +0530 Subject: [PATCH] Add cut rod problem --- Dynamic Programming/Cut Rod.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Dynamic Programming/Cut Rod.cpp diff --git a/Dynamic Programming/Cut Rod.cpp b/Dynamic Programming/Cut Rod.cpp new file mode 100644 index 000000000..90e12a532 --- /dev/null +++ b/Dynamic Programming/Cut Rod.cpp @@ -0,0 +1,29 @@ +/*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.*/ + +#include +using namespace std; +int cutrod(int p[],int n) +{ + int r[n+1]; + r[0]=0; + for(int j=0;j