Cod sursa(job #2506404)
| Utilizator | Data | 7 decembrie 2019 23:16:38 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <bits/stdc++.h>
#define GMAX 10005
using namespace std;
ifstream f ("rucsac.in");
ofstream g ("rucsac.out");
int n , weight , value , weight_max;
int a[GMAX];
int main()
{
int ans = 0 , i , j;
f >> n >> weight_max;
for(i = 1 ; i <= n ; i++)
{
f >> weight >> value;
for(j = weight_max - weight ; j >= 0 ; j--)
if(a[j + weight] <= a[j] + value)
{
a[j + weight] = a[j] + value;
ans = max(ans , a[j + weight]);
}
}
g << ans;
return 0;
}
