Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3. #include "optimization.h"
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int first[22];
  9. int first_sum[32770];
  10.  
  11. int second[22];
  12. int second_sum[32770];
  13.  
  14. int main() {
  15. ios_base::sync_with_stdio(false);
  16. cin.tie(0);
  17. cout.tie(0);
  18. int n;
  19. cin >> n;
  20. for (int i = 0; i < (n / 2); i++) {
  21. cin >> first[i];
  22. }
  23. int size_first = n / 2;
  24. if (n % 2 != 0) {
  25. n++;
  26. }
  27. int size_second = n / 2;
  28. for (int i = 0; i < (n / 2); i++) {
  29. cin >> second[i];
  30. }
  31. for (int i = 0; i < (1 << size_first); i++) {
  32. first_sum[i] = 0;
  33. }
  34. for (int i = 0; i < (1 << size_second); i++) {
  35. second_sum[i] = 0;
  36. }
  37. for (int A = 0; A < (1 << size_first); A++) {
  38. for (int i = 0; i < size_first; i++) {
  39. if ((A >> i) & 1) {
  40. first_sum[A] += first[i];
  41. }
  42. }
  43. }
  44. for (int A = 0; A < (1 << size_first); A++) {
  45. // cout << first_sum[A] << ' ';
  46. }
  47. // cout << endl;
  48.  
  49. for (int B = 0; B < (1 << size_second); B++) {
  50. for (int i = 0; i < size_second; i++) {
  51. if ((B >> i) & 1) {
  52. second_sum[B] += second[i];
  53. }
  54. }
  55. }
  56.  
  57. for (int B = 0; B < (1 << size_second); B++) {
  58. // cout << second_sum[B] << ' ';
  59. }
  60. cout << endl;
  61.  
  62. sort(second_sum, second_sum + size_second);
  63. sort(first_sum, first_sum + size_first);
  64. int c;
  65. long long ans = 0;
  66. cin >> c;
  67. int j = (1 << size_second) - 1;
  68. for (int i = 0; i < (1 << size_first); i++) {
  69. int k = upper_bound(second_sum,second_sum + size_second, c - first_sum[i]) - second_sum ;
  70. // cout << i <<' ' << k << endl;
  71. //if (k != size_second -2 || second_sum[size_second - 2] <= c-first_sum[i] ) {
  72. ans += k + 1;
  73. //}
  74. //cout <<"cycle: " << ans << endl;
  75. }
  76. cout << ans;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement