Advertisement
drof13

Untitled

Nov 1st, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <map>
  6. #include <set>
  7. #include <string>
  8. #include <vector>
  9. #include <algorithm>
  10.  
  11. #define int long long
  12. #define pb push_back
  13.  
  14. using namespace std;
  15.  
  16. void permutation(vector<int>& v, int n, int k, int countNull, int needNull) {
  17.     if (n == 0) {
  18.         if (countNull == needNull) {
  19.             for (auto i : v) {
  20.                 cout << i;
  21.             }
  22.             cout << '\n';
  23.         }
  24.         return;
  25.     }
  26.     for (int i = 0; i <= 1; i++) {
  27.         if (countNull == needNull) {
  28.             v.push_back(1);
  29.             permutation(v, n - 1, k, countNull, needNull);
  30.             v.pop_back();
  31.             break;
  32.         }
  33.         if (i == 0) {
  34.             countNull++;
  35.         }
  36.         v.push_back(i);
  37.         permutation(v, n - 1, k, countNull, needNull);
  38.         v.pop_back();
  39.         countNull--;
  40.     }
  41. }
  42.  
  43. signed main() {
  44.     ios_base::sync_with_stdio(0);
  45.     cin.tie(0);
  46.     cout.tie(0);
  47.     int n, k;
  48.     cin >> n >> k;
  49.     vector<int> v;
  50.     int countNull = 0;
  51.     int needNull = n - k;
  52.     permutation(v, n, k, countNull, needNull);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement