Pagini recente » Cod sursa (job #1786340) | Cod sursa (job #2157981) | Cod sursa (job #983000) | Cod sursa (job #2070654) | Cod sursa (job #3241215)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
const int MAX_WEIGHT = 5e3;
const int MAX_OBJECTS = 1e4;
int n, g;
int w[MAX_OBJECTS + 1], p[MAX_OBJECTS + 1], maxProfit[MAX_WEIGHT + 1][MAX_OBJECTS + 1];
int answer;
void solve(int weight, int profit, int index) {
if (weight > g || index > n) {
return;
}
answer = max(answer, profit);
solve(weight + w[index + 1], profit + p[index + 1], index + 1);
solve(weight, profit, index + 1);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
fin >> n >> g;
for (int i = 1; i <= n; ++i) {
fin >> w[i] >> p[i];
}
solve(0, 0, 0);
fout << answer;
return 0;
}