Cod sursa(job #2048785)
| Utilizator | Data | 26 octombrie 2017 16:24:30 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int n,gmax,w,p,ans, v[10001];
int main()
{
f >> n >> gmax;
for(int i=1; i<=n; i++)
{
f >> w >> p;
for(int j = gmax-w; j>0; j--)
{
if(v[j] && v[j+w] < v[j]+p)
{
v[j+w] = v[j]+p;
ans = max(ans,v[j+w]);
}
}
v[w] = max (v[w],p);
ans = max(ans, v[w]);
}
cout << ans;
return 0;
}
