Cod sursa(job #2738609)
| Utilizator | Data | 6 aprilie 2021 09:34:55 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
#include <algorithm>
#define iter for (int j = 1; j <= N; ++j)
using namespace std;ifstream i("rucsac.in");ofstream o("rucsac.out");int N,G,val[5003],w[5003],DP[2][10003];void in(){i>>N>>G;iter i>>w[j]>>val[j];}void s(){iter{for(int g=1;g<w[j];++g)DP[1][g]=DP[0][g];for(int g=w[j];g<=G;++g)DP[1][g]=max(DP[0][g],DP[0][g-w[j]]+val[j]);for(int g=1;g<=G;++g)DP[0][g]=DP[1][g];}o<<DP[0][G];}int main(){in();s();}
