Cod sursa(job #2945226)
| Utilizator | Data | 23 noiembrie 2022 16:47:21 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
using namespace std;
const int GMAX = 1e5+1;
const int MAX = 5e3+1;
ifstream cin("rucsac.in");
ofstream cout("rucsac.out");
int dp[GMAX], c , p, n , g ;
int main()
{
cin >> n >> g;
for(int i = 1; i <= n ; i++){
cin >> c >> p;
for(int j = g ; j ; j--){
if(j-c < 0) continue;
dp[j] = max(dp[j],dp[j-c]+p);
}
}
cout << dp[g];
return 0;
}
