Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Nguyen Huu Hoang Minh
- #include <bits/stdc++.h>
- #define sz(x) int(x.size())
- #define all(x) x.begin(),x.end()
- #define reset(x) memset(x, 0,sizeof(x))
- #define pb push_back
- #define mp make_pair
- #define fi first
- #define se second
- #define N 2005
- #define remain(x) if (x > MOD) x -= MOD
- #define ii pair<int, int>
- #define iiii pair< ii , ii >
- #define viiii vector< iiii >
- #define vi vector<int>
- #define vii vector< ii >
- #define bit(x, i) (((x) >> (i)) & 1)
- #define Task "test"
- #define int long long
- using namespace std;
- typedef long double ld;
- const int inf = 1e10;
- const int minf = -1e10;
- int n, w;
- int W[N], V[N];
- bool vst[N];
- int ans = 0;
- vector<int> res;
- void readfile()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- cin >> n >> w;
- for(int i=1; i<=n; i++) cin >> W[i] >> V[i];
- }
- void ghikq()
- {
- res.clear();
- for(int i=1; i<=20; i++)
- {
- if (vst[i]) res.pb(i);
- }
- }
- void quaylui(int x, int res, int wei)
- {
- if (ans < res)
- {
- ans = res;
- ghikq();
- }
- if (x+1>n) return;
- //chọn vật thứ i
- if (W[x+1] + wei <= w){
- vst[x+1] = true;
- quaylui(x+1,res+V[x+1],wei+W[x+1]);
- vst[x+1] = false;
- }
- //không chọn vật thứ i
- quaylui(x+1,res,wei);
- }
- void proc()
- {
- if (W[1] <= w) vst[1] = true, quaylui(1,V[1],W[1]), vst[1] = false;
- quaylui(1,0,0);
- cout << ans << '\n';
- for(auto x : res) cout << x << ' ';
- }
- signed main()
- {
- readfile();
- proc();
- return 0;
- }
Add Comment
Please, Sign In to add comment