Cod sursa(job #2158551)
Utilizator | Data | 10 martie 2018 13:48:34 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 65 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int main()
{ int dp[10001],n,gmax;
in>> n;
in>> gmax;
for(int i=1;i<=n;i++){
int g,p;
in>> g;
in>> p;
for(int j=gmax;j>=g;--j){
dp[j]=max(dp[j],dp[j-g]+p);
}
}
out<< dp[gmax];
return 0;
}