Alex_tz307

Counting Subsets CPH - page 115

Sep 17th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int N;
  7.     cin >> N;
  8.     vector < int > values(1 << N);
  9.     for(int& x : values)
  10.         cin >> x;
  11.     vector < int > sum(1 << N);
  12.     for(int i = 0; i < (1 << N); ++i)
  13.         sum[i] = values[i];
  14.     for(int k = 0; k < N; ++k)
  15.         for(int s = 0; s < (1 << N); ++s)
  16.             if(s & (1 << k))
  17.                 sum[s] += sum[s ^ (1 << k)];
  18.     cout << sum[(1 << N) - 1];
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment