Cod sursa(job #3230099)
| Utilizator | Data | 19 mai 2024 11:26:06 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <fstream>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int n, g, dp[2][20010], i, j;
bool ths, othr = 1;
pair<int, int> a;
int main()
{
in >> n >> g;
for (i = 1; i <= n; i++)
{
in >> a.first >> a.second;
for (j = 1; j <= g; j++)
{
dp[ths][j] = dp[othr][j];
if (a.first <= j)
dp[ths][j] = max(dp[ths][j], dp[othr][j - a.first] + a.second);
}
ths = 1 - ths;
othr = 1 - othr;
}
out << dp[1][g];
return 0;
}