Pagini recente » Cod sursa (job #1220586) | Cod sursa (job #824982) | Cod sursa (job #2526648) | Cod sursa (job #673216) | Cod sursa (job #2426994)
#include <fstream>
#include <string>
#include <vector>
using namespace std;
string const inFile = "rucsac.in";
string const outFile = "rucsac.out";
ifstream Read(inFile);
ofstream Write(outFile);
int main() {
unsigned n;
unsigned G;
Read >> n;
Read >> G;
vector<unsigned> line(G + 1, 0);
unsigned weight;
unsigned value;
unsigned i;
int j;
for (i = 0; i < n; ++i) {
Read >> weight;
Read >> value;
for (j = G - weight; j >= 0; --j) {
line[j + weight] = max(line[j + weight], line[j] + value);
}
}
Write << line[G];
return 0;
}