Pagini recente » Cod sursa (job #540307) | Cod sursa (job #2157608) | Cod sursa (job #2660420) | Cod sursa (job #2652450) | Cod sursa (job #901102)
Cod sursa(job #901102)
#include <fstream>
#include <iostream>
using namespace std;
fstream f("rucsac.in" , ios::in), fo("rucsac.out", ios::out);
int mat[5001][10001];
int main()
{
int n,g,v,w;
f>>n>>g;
for(int i=1;i<=n;i++)
{
f>>w>>v;
for(int j=w;j<=g;j++)
{
if(mat[i-1][j-w]+v>mat[i-1][j])
mat[i][j]=mat[i-1][j-w]+v;
else
mat[i][j]=mat[i-1][j];
}
}
/* for(int i=1;i<=n;i++)
{
for(int j=1;j<=g;j++)
fo<<mat[i][j]<<" ";
fo<<endl;
}*/
fo<<mat[n][g];
return 0;
}