Advertisement
7oSkaaa

I - Batman Weapons

Aug 13th, 2022
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  6. #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
  7. #define fixed(n) fixed << setprecision(n)
  8. #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  9. #define fill(vec, value) memset(vec, value, sizeof(vec));
  10. #define mul_mod(a, b, m) (((a % m) * (b % m)) % m)
  11. #define add_mod(a, b, m) (((a % m) + (b % m)) % m)
  12. #define all(vec) vec.begin(), vec.end()
  13. #define rall(vec) vec.rbegin(), vec.rend()
  14. #define sz(x) int(x.size())
  15. #define debug(x) cout << #x << ": " << (x) << "\n";
  16. #define fi first
  17. #define se second
  18. #define ll long long
  19. #define ull unsigned long long
  20. #define Mod  1'000'000'007
  21. #define OO 2'000'000'000
  22. #define EPS 1e-9
  23. #define PI acos(-1)
  24. template < typename T = int > using Pair = pair < T, T >;
  25. vector < string > RET = {"NO", "YES"};
  26.  
  27. template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {
  28.     for (auto &x : v) in >> x;
  29.     return in;
  30. }
  31.  
  32. template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) {
  33.     for (const T &x : v) out << x << ' ';
  34.     return out;
  35. }
  36.  
  37. constexpr int N = 15, M = 1e3 + 5;
  38. vector < int > a(M), b(M), dp(1 << N, OO);
  39. vector < vector < int > > c(M);
  40.  
  41. void Solve(){
  42.     int n, m;
  43.     cin >> n >> m;
  44.     for(int i = 1; i <= m; i++){
  45.         cin >> a[i] >> b[i];
  46.         c[i] = vector < int > (b[i] + 5);
  47.         for(int j = 1; j <= b[i]; j++)
  48.             cin >> c[i][j];
  49.     }
  50.     dp[0] = 0;
  51.     for(int key = 1; key <= m; key++){
  52.         int boxes = 0;
  53.         for(int j = 1; j <= b[key]; j++)
  54.             boxes |= (1 << (c[key][j] - 1));
  55.         for(int mask = 0; mask < (1 << n); mask++)
  56.             dp[mask | boxes] = min(dp[mask | boxes], dp[mask] + a[key]);
  57.     }
  58.     if(dp[(1 << n) - 1] == OO) dp[(1 << n) - 1] = -1;
  59.     cout << dp[(1 << n) - 1] << "\n";
  60. }
  61.  
  62. int main(){
  63.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  64.     int t = 1;
  65.     // cin >> t;
  66.     while(t--)
  67.         Solve();
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement