Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int n;
  10.  
  11. vector<bool> dp;
  12. vector<vector<int>> pr;
  13. vector<int> a, b, c;
  14.  
  15.  
  16. int current_mood(int mask)
  17. {
  18.     int ans{0};
  19.     for (int i = 0; i < n; ++i)
  20.         ans += ((mask >> i) & 1) * c[i];
  21.     return ans;
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27.     std::ios::sync_with_stdio(false);
  28.     int k, mood;
  29.     cin >> n >> k;
  30.     int max_mask = (1 << n);
  31.     dp.resize(max_mask);
  32.     pr.resize(max_mask);
  33.     a.resize(n); b.resize(n); c.resize(n);
  34.  
  35.     for (int i = 0; i < n; ++i)
  36.         cin >> a[i] >> b[i] >> c[i];
  37.     dp[0] = true;
  38.     for (int mask = 0; mask < max_mask; ++mask) {
  39.         if (!dp[mask])
  40.             continue;
  41.         mood = k + current_mood(mask);
  42.         //cout << "MOOD: " << mood << endl;
  43.         for (int i = 0; i < n; ++i) {
  44.             if ((mask >> i) & 1)
  45.                 continue;
  46.             if (mood >= a[i] && mood <= b[i]) {
  47.                 dp[mask | (1 << i)] = true;
  48.                 pr[mask | (1 << i)] = pr[mask];
  49.                 pr[mask | (1 << i)].push_back(i + 1);
  50.             }
  51.             else
  52.                 dp[mask | (1 << i)] = false;
  53.         }
  54.     }
  55.  
  56.     int ans = 0;
  57.     for (int mask = 0; mask < max_mask; ++mask)
  58.         if (dp[mask] && pr[mask].size() > pr[ans].size())
  59.                 ans = mask;
  60.  
  61.     cout << pr[ans].size() << '\n';
  62.     for (const int& x : pr[ans])
  63.         cout << x << ' ';
  64.  
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement