Cod sursa(job #3238218)
| Utilizator | Data | 23 iulie 2024 14:32:29 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
#include <cstring>
using namespace std;
#define MAX_N 5001
#define MAX_W 10001
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int main()
{
int n, total_w;
int w[MAX_N], p[MAX_N], dp[MAX_W];
memset(dp, 0, sizeof(dp));
fin >> n >> total_w;
for (int i = 0; i < n; ++i)
{
fin >> w[i] >> p[i];
for (int j = total_w; j >= w[i]; --j)
{
dp[j] = max(dp[j], dp[j - w[i]] + p[i]);
}
}
fout << dp[total_w];
return 0;
}