Cod sursa(job #2511319)
| Utilizator | Data | 18 decembrie 2019 19:45:43 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.38 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n, gmax, v[10005], profit, greutate;
int main()
{
cin >> n >> gmax;
for (int i = 1; i <= n; i++)
{
cin >> greutate >> profit;
for (int j = gmax; j >= greutate; j--)
if (v[j] < v[j - greutate] + profit)
v[j] = v[j - greutate] + profit;
}
cout << v[gmax];
}
