Cod sursa(job #1724704)
| Utilizator | Data | 3 iulie 2016 23:38:43 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int n, G, d[10001],g,p;
int main(){
int i,j;
freopen("rucsac.in", "r", stdin);
freopen("rucsac.out", "w", stdout);
scanf("%d %d", &n, &G);
for (i = 1; i <= G; i++)
d[i] = -1;
for (i = 1; i <= n; i++){
scanf("%d %d", &g, &p);
for (j = G - g; j >= 0; j--){
if (d[j] != -1){
if (d[j + g] < d[j] + p)
d[j + g] = d[j] + p;
}
}
}
int max = 0;
for (i = 1; i <= G; i++)
if (max < d[i])
max = d[i];
printf("%d", max);
return 0;
}