Cod sursa(job #1476424)
Utilizator | Data | 25 august 2015 09:26:59 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <stdio.h>
using namespace std;
const int MX = 12345;
int N,G;
int Sol[MX];
int main()
{
freopen("rucsac.in","r",stdin);
freopen("rucsac.out","w",stdout);
scanf("%d %d",&N,&G);
while (N--)
{
int W,P;
scanf("%d %d",&W,&P);
for (int j = G - W;j >= 0;j--)
if (Sol[j + W] < Sol[j] + P)
Sol[j + W] = Sol[j] + P;
}
printf("%d\n",Sol[G]);
return 0;
}