Cod sursa(job #2205926)
Utilizator | Data | 20 mai 2018 16:51:12 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int n, g, w, p, dp[10010], mx;
int main()
{
in>>n>>g;
for(int i=1; i<=n; i++)
{
in>>w>>p;
for(int q=g-w; q>=0; q--)
if(q==0 || dp[q])
dp[q+w]=max(dp[q+w], dp[q]+p);
}
for(int i=1; i<=g; i++)
mx=max(mx, dp[i]);
out<<mx;
return 0;
}