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