Cod sursa(job #902736)
Utilizator | Data | 1 martie 2013 16:28:37 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <fstream>
#include <iostream>
using namespace std;
fstream f("rucsac.in" , ios::in), fo("rucsac.out", ios::out);
int mat[10001];
int main()
{
int n,g,v,w,s=0;
f>>n>>g;
for(int i=1;i<=n;i++)
{
f>>w>>v;
for(int j=g-w;j>=0;j--)
if(mat[j]+v>mat[j+w])
{
mat[j+w]=mat[j]+v;
if ( mat[j+w]>s)
s=mat[j+w];
}
}
fo<<s;
return 0;
}