Cod sursa(job #2138822)
Utilizator | Data | 21 februarie 2018 21:35:29 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int n,g,m,maxx;
int ans[2][10001];
int main()
{
in>>n>>g;
int t = 0;
for(int i = 1;i<=n;i++)
{
int w,p;
in>>w>>p;
for(int j = 0;j<=g;j++)
{
if(j>=w)
ans[t][j]=max(ans[1-t][j],ans[1-t][j-w]+p);
else
ans[t][j]=ans[1-t][j];
}
t=!t;
}
out<<ans[!t][g];
return 0;
}