Cod sursa(job #2482828)
| Utilizator | Data | 28 octombrie 2019 21:48:17 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <fstream>
#define NMAX 5000
#define GMAX 10000
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
long long n, G, b, dp[3][GMAX+10];
pair <long long, long long> v[NMAX+10];
int main()
{
f >> n >> G;
for(int i=1; i<=n; i++)
{ f >> v[i].first >> v[i].second;
b = 1 - b;
for(int j=1; j<v[i].first; j++) dp[b][j] = dp[1-b][j];
for(int j=v[i].first; j<=G; j++) dp[b][j] = max(dp[1-b][j], dp[1-b][j-v[i].first] + v[i].second);
}
g << dp[b][G] << '\n';
return 0;
}
