Mai intai trebuie sa te autentifici.
Cod sursa(job #1889989)
Utilizator | Data | 22 februarie 2017 23:01:22 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 85 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.58 kb |
#include <cstdio>
#include <iostream>
using namespace std;
const int nmx = 10002;
int dp[nmx];
int main()
{
freopen("rucsac.in", "r", stdin);
freopen("rucsac.out", "w", stdout);
int gmax = 0,n,x;
scanf("%d %d", &n, &x);
for(int i = 1; i <= n; ++i)
{
int val,greutate;
scanf("%d %d", &greutate, &val);
gmax += greutate;
gmax = min(gmax,x);
for(int j = gmax; j >= greutate; --j)
dp[j] = max(dp[j],dp[j-greutate] + val);
}
printf("%d\n", dp[gmax]);
return 0;
}