Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CutRod(BottomUp)
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////////CutRod(BottomUp):understanding dynamic programming with rod cutting problem(bottom-up approach) //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){ for(int i=1;i<=n;i++){ int MaxR=-1*K; for(int j=1;j<=i;j++){ MaxR=max(MaxR,p[j]+r[i-j]); } r[i]=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
pac update
sdfsdf
3
2
Изволов#2
DailyExchRate2
30 აპრილი
Web Browser History
OverloadFunc
СПКИ АП КЭП 3