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. s[0]=0;
  25. for (long long mask=1; mask<MASK(n); mask++)
  26. {
  27. long long tmp =mask&-mask;
  28. s[mask]=s[tmp]+s[tmp^mask];
  29. }
  30.  
  31. }
  32. int main()
  33. {
  34. ios_base::sync_with_stdio(0);
  35. cin.tie(0);
  36. input();
  37. solve();
  38. return 0;
  39. }
  40.  
  41.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty