Cod sursa(job #2854599)
Utilizator | Data | 21 februarie 2022 15:25:16 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int dp[10010];
int main()
{
int n, g;
fin>>n>>g;
for(int i = 1; i <= n; i++){
int w, p;
fin>>w>>p;
for(int j = g; j >= w; j--){
dp[j] = max(dp[j], dp[j-w] + p);
}
}
fout<<dp[g];
return 0;
}