Cod sursa(job #2286339)
| Utilizator | Data | 20 noiembrie 2018 10:16:16 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <fstream>
#define NMAX 5010
#define WMAX 10010
std::ifstream fin("rucsac.in");
std::ofstream fout("rucsac.out");
int n, wMax;
int dp[WMAX];
int w[NMAX], p[NMAX];
inline int max(int x, int y) {
return x > y ? x : y;
}
int main() {
int i, j;
fin >> n >> wMax;
for (i = 1; i <= n; i++)
fin >> w[i] >> p[i];
for (i = 1; i <= n; i++)
for (j = wMax; j >= 1; j--)
if (w[i] <= j)
dp[j] = max(dp[j], dp[j - w[i]] + p[i]);
else
dp[j] = dp[j];
fout << dp[wMax] << '\n';
fout.close();
return 0;
}
