fork download
  1. #include<bits/stdc++.h>
  2. #define MASK(i) (1<<(i))
  3. #define BIT(x,i) (((x)>>(i))&1)
  4. using namespace std;
  5. const long long MaxN = 17;
  6. const long long MaxDP = 1<<MaxN;
  7. long long n,a[MaxN],s[MaxDP];
  8. void input()
  9. {
  10. cin >> n;
  11. for (long long i=0; i<n; i++)
  12. {
  13. cin >> a[i];
  14. }
  15. }
  16. void solve()
  17. {
  18.  
  19. // tính tổng mọi tập con của a[0,...,n]
  20. for (long long i=0; i<n; i++)
  21. {
  22. s[MASK(i)]=a[i];
  23. }
  24. for (long long mask=0; mask<MASK(n); mask++)
  25. {
  26. long long tmp =mask&-mask;
  27. s[mask]=s[tmp]+s[tmp^mask];
  28. }
  29.  
  30. }
  31. int main()
  32. {
  33. ios_base::sync_with_stdio(0);
  34. cin.tie(0);
  35. input();
  36. solve();
  37. return 0;
  38. }
  39.  
  40.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty