Playing code does not go heart will fall in the pit.
Below is the code:
1 //1146. Drug-collecting2 //t = Total time3 //m indicates the number of herbs4 //W indicates the time of the drug adoption5 //v denotes herbal value6#include <iostream>7 using namespacestd;8 9 #defineMAX (A, b) a>b?a:bTen One intMaxValue (intW[],intV[],intMintt) { A intmax[m+1][t+1]; - for(inti =0; I <= t; i++) { - if(i>=w[1]) max[1][i] = v[1];//I was just beginning to make the w[1 here] w[i]. Next time to hit the code must go heart. the Elsemax[1][i] =0; - } - for(inti =2; I <= m; i++) { - for(intj =0; J <= T; J + +) { + if(J<w[i]) max[i][j] = max[i-1][j]; - Else { +MAX[I][J] = MAX (max[i-1][J], (max[i-1][j-w[i]]+v[i])); A } at } - } - returnMax[m][t]; - } - - intMain () { in intT, M; -Cin>>t>>m; to intw[m+1], v[m+1]; + for(inti =1; I <= m; i++) cin>>w[i]>>V[i]; -Cout<<maxvalue (w,v,m,t) <<Endl; the return 0; *}
Sicily 1146 Medicine (dynamic Regulation)