Cod sursa(job #2046099)
| Utilizator | Data | 23 octombrie 2017 14:11:39 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
#define lim 10010
int n,dp[lim],gmax,g,p,rez=-1;
int main()
{
fin>>n>>gmax;
for (int i=1; i<=n; i++)
{
fin>>g>>p;
for (int j=gmax-g; j>0; j--)
if (dp[j] && dp[j+g] < dp[j]+p)
dp[j+g] = dp[j]+p, rez = max (rez, dp[j+g]);
dp[g] = max (dp[g], p);
rez = max (rez, dp[g]);
}
fout<<rez;
fin.close();
fout.close();
return 0;
}
