Cod sursa(job #3354968)
| Utilizator | Data | 21 mai 2026 13:43:43 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int dp[10005];
int main() {
int n, g;
fin >> n;
vector <int> dp(g + 1, 0);
for (int i = 1; i <= n; i++) {
int w_object, p_object;
fin >> w_object >> p_object;
for (int w = g; w >= w_object; w--) {
dp[w] = max(dp[w], dp[w - w_object] + p_object);
}
}
fout << dp[g] << '\n';
return 0;
}