Cod sursa(job #1758140)
| Utilizator | Data | 16 septembrie 2016 17:06:40 | |
|---|---|---|---|
| Problema | Problema rucsacului | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
#include <vector>
#include <bitset>
#define GMax 10001
#define NMax 5001
using namespace std;
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int n, g;
int ruc[GMax];
void read() {
in>>n>>g;
for (int i=1;i<=n;i++) {
int weight, profit;
in>>weight>>profit;
for (int j=g;j>=weight;j--) {
if (ruc[j-weight] + profit > ruc[j])
ruc[j] = ruc[j-weight]+profit;
}
}
}
int main() {
read();
out<<ruc[g]<<'\n';
in.close();
out.close();
return 0;
}
