Advertisement
Korotkodul

Шаг в буд_Отбор_N6

Nov 1st, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <set>
  5. #include <string>
  6. #include <algorithm>
  7. using namespace std;
  8. using ll = long long;
  9. void co(vector <int> v){
  10.     for (auto x: v) cout<<x<<' ';
  11.     cout<<'\n';
  12. }
  13.  
  14. int main()
  15. {
  16.     int n;
  17.     cin>>n;
  18.     int R;
  19.     cin>>R;
  20.     vector <int> r(n);
  21.     for (int &x: r) cin>>x;
  22.     int ans = 0;
  23.     //vector <int> now;
  24.     //vector <vector <int> > all;
  25.     for (int mask = 0; mask < (1 << n); mask++) {
  26.         //now.clear();
  27.         int Ri = 0;
  28.         for (int i = 0; i < n; ++i) {
  29.             if (mask & (1 << i)) {
  30.                 //cout << 1;
  31.                 Ri += r[i];
  32.                 //now.push_back(r[i]);
  33.             }
  34.             /*else {
  35.  
  36.                 //cout << 0;
  37.             }*/
  38.         }//cout << '\n';
  39.         if (Ri == R) {
  40.                 ans++;
  41.                 //all.push_back(now);
  42.                 //co(now);
  43.                 //cout<<"YES"<<endl;
  44.         }
  45.     }
  46.     /*
  47.     cout<<'\n';
  48.     co(r);
  49.     cout<<"all\n";
  50.     for (auto x: all) co(x);
  51.     cout<<"ans = ";*/
  52.     cout<<ans;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement