Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n;
- int cost[105], weight[105];
- long long dp[101][100001];
- long long rek(int att, int cost_left) {
- if(cost_left == 0) {
- return 0;
- }
- if(att==n)
- {
- return 2e9;
- }
- if(dp[att][cost_left] != -1) {
- return dp[att][cost_left];
- }
- long long maks = 1e15;
- maks = min(maks, rek(att + 1, cost_left)); // sto ako ne go zememe ovoj element
- if(cost_left - cost[att] >= 0) {
- maks = min(maks, rek(att + 1, cost_left - cost[att]) + weight[att]); // sto ako go zememe ovoj element
- }
- dp[att][cost_left] = maks;
- return maks;
- }
- int main()
- {
- cin >> n;
- int max_weight;
- cin >> max_weight;
- for(int i = 0; i < n; i++) {
- cin >> weight[i] >> cost[i];
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j <= 100000; j++) {
- dp[i][j] = -1;
- }
- }
- int rez;
- for(int j = 0; j <= 100000; j++) {
- if(rek(0,j)<=max_weight)
- {
- rez=j;
- }
- }
- cout<<rez;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement