Cod sursa(job #2617943)
| Utilizator | Data | 23 mai 2020 13:09:58 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("rucsac.in");
ofstream fout ("rucsac.out");
int v[10001];
int main()
{
int G, n, i, j, g_obiect, pret, maxx;
fin >> n >> G;
for(i=1;i<=n;i++)
{
fin >> g_obiect >> pret;
for(j=G-g_obiect ; j>0 ; j--)
{
if(v[j]>0)
v[j+g_obiect]=max(v[j]+pret , v[j+g_obiect]);
}
v[g_obiect]=max(pret , v[g_obiect]);
}
maxx=0;
for(i=1;i<=G;i++)
if(maxx<v[i])
maxx=v[i];
fout << maxx;
return 0;
}
