Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CutRod
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////////CutRod:understanding dynamic programming with rod cutting problem //this code is created by Rezaul Hoque on September 12,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; //////////////////////////////////////////////////////////////////////////// #include <iostream> const int K=100000; const int n=8; int max(int a,int b){ return (a>b)?a:b; } class RC{ int r[n+1]; int price[n]; public: RC(int c[],int n){ int i; r[0]=0; for(i=1;i<=n;i++){ r[i]=-1*K; price[i]=c[i]; } } int CutRod(int p[],int n){ if(r[n]>=0) return r[n]; int MaxR=-1*K; for(int i=1;i<=n;i++){ MaxR=max(MaxR,p[i]+CutRod(p,n-i)); } r[n]=MaxR; return r[n]; } }; int main() { int a[]={0,1,5,8,9,10,17,17,20}; RC rod(a,8); std::cout<<rod.CutRod(a,8); return 0; }
run
|
edit
|
history
|
help
0
multiply_without_asterisk
1234
Stock buy/sell
Conjuntos - analizar la lógica
BubDoubArray2
My billing system
Luces led con relé
Sorting Array
HeapSort
TraiectorieIdeala