Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- #define Task "test"
- //#define READFILE freopen(Task".INP", "r", stdin)
- #define READFILE freopen("test.inp", "r", stdin)
- #define WRITEFILE freopen(Task".OUT", "w", stdout)
- #define oo 1e18
- #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- #define mp make_pair
- #define pb push_back
- #define X first
- #define Y second
- #define watch(x) cout << (#x) << " = " << x << endl
- #define debug(x) cout << (#x) << " = " << x << endl
- #define all(x) x.begin(), x.end()
- #define sz(x) x.size()
- #define endl '\n'
- #define max3(a,b,c) max(max(a, b), c)
- #define max4(a,b,c,d) max(max(a, b), max(c, d))
- #define min4(a,b,c,d) min(min(a, b), min(c, d))
- #define debug4(a,b,c,d) watch(a);watch(b);watch(c);watch(d)
- #define ever (;true;)
- #define maxn 505
- using namespace std;
- typedef pair < int, int > ii;
- typedef pair < int, ii > iii;
- typedef pair < ii, ii > iiii;
- typedef vector < int > vi;
- typedef vector < ii > vii;
- typedef vector < vi > vvi;
- typedef vector < iii > viii;
- typedef vector < vii > vvii;
- typedef vector < iiii > viiii;
- typedef vector < vvi > vvvi;
- const int MOD = 1e9 + 7;
- const int dx[] = {-1, 1, 0, 0};
- const int dy[] = {0, 0, -1, 1};
- const int N = 1e3 + 5;
- const int K = 10 + 5;
- int n, m;
- int w[N], v[N];
- int Vres = 0;
- int nRes = 0, res[N];
- //mảng chứa gói hàng kết quả
- int nCur = 0, cur[N];
- //mảng chứa gói hàng đang xét
- void init(){
- FAST;
- #ifndef ONLINE_JUDGE
- READFILE;
- freopen("test.out", "w", stdout);
- #endif // ONLINE_JUDGE
- cin >> n >> m;
- for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i];
- }
- void btr(int i, int curW, int curV){
- //ĐÃ xét i-1 vật đầu tiên, sử dụng curW trọng lượng và có giá trị là curV
- //nếu đã xét hết n vật thì cập nhật kết quả
- if (i == n + 1){
- if (Vres < curV){
- Vres = curV;
- nRes = nCur;
- for (int i = 1; i <= nRes; ++i) res[i] = cur[i];
- }
- return;
- }
- //nếu bỏ qua vật thứ i
- btr(i + 1, curW, curV);
- //nếu mang theo vật thứ i
- if (curW + w[i] <= m){
- //cập nhật mảng gói hàng đang xét
- cur[++nCur] = i;
- btr(i + 1, curW + w[i], curV + v[i]);
- //trả lại trạng thái ban đầu
- --nCur;
- }
- }
- signed main(){
- init();
- btr(1, 0, 0);
- cout << Vres << endl;
- for (int i = 1; i <= nRes; ++i) cout << res[i] << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement