Cod sursa(job #1974257)
Utilizator | Data | 27 aprilie 2017 09:21:04 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
#include <cstring>
#include <stack>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
#define ll long long
const ll GMax = 1e4 + 5;
int N,G;
ll dp[GMax];
int main() {
in>>N>>G;
for (int i=1;i<=N;++i) {
int weight,value;
in>>weight>>value;
for (int j=G;j - weight >= 0;--j) {
dp[j] = max(dp[j],dp[j - weight] + value);
}
}
out<<dp[G]<<'\n';
in.close();out.close();
return 0;
}