Cod sursa(job #2379090)
Utilizator | Musat Mihai-Robert mihaimusat.1998 | Data | 12 martie 2019 21:16:36 |
---|---|---|---|
Problema | Problema rucsacului | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
#define nmax 5001
#define gmax 10001
using namespace std;
int main()
{
ifstream fin("a.in");
ofstream fout("a.out");
int n, g;
int w[nmax], p[nmax], dp[gmax];
fin>>n>>g;
for(int i=1; i<=n; i++) {
fin>>w[i]>>p[i];
}
int sol = 0;
for(int i=1; i<=n; i++) {
for(int j=g; j>=w[i]; j--) {
dp[j] = max(dp[j-w[i]]+p[i], dp[j]);
if(dp[j]>sol) {
sol=dp[j];
}
}
}
fout<<sol<<endl;
return 0;
}