Cod sursa(job #1958508)
Utilizator | Data | 8 aprilie 2017 14:18:32 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <bitset>
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
const int GMax = 1e4 + 5;
int N,G;
int dp[GMax];
int main() {
in>>N>>G;
for (int i=1;i<=N;++i) {
int greutate,profit;
in>>greutate>>profit;
for (int j=G;j>0;--j) {
if (j-greutate>=0 && dp[j] < dp[j-greutate] + profit) {
dp[j] = max(dp[j],dp[j-greutate] + profit);
}
}
}
out<<dp[G];
in.close();out.close();
return 0;
}