Cod sursa(job #2652166)
| Utilizator | Data | 24 septembrie 2020 15:13:15 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.4 kb |
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
int n, g;
int dp[10041];
int main(){
// ios_base::sync_with_stdio(false);
fin >> n >> g;
for(int i = 0; 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;
}