Iamtui1010

somayman.cpp

Aug 13th, 2022 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include<iostream>
  2. #include<set>
  3.  
  4. #define long long long
  5. #define nln '\n'
  6.  
  7. using namespace std;
  8.  
  9. set<int> a;
  10.  
  11. void put(long i, long n, long x, long y, long sum)
  12. {
  13.     if (i > n){
  14.         a.insert(sum);
  15.         return;
  16.     }
  17.     put(i+1, n, x, y, sum*10+x);
  18.     put(i+1, n, x, y, sum*10+y);
  19. }
  20.  
  21. int main()
  22. {
  23.     cin.tie(0)->sync_with_stdio(0);
  24.     cout.tie(0)->sync_with_stdio(0);
  25.     //freopen("somayman.inp", "r", stdin);
  26.     long n;
  27.     cin >> n;
  28.     //Input
  29.     for (long i = 1; i <= 9; ++i)
  30.         for (long j = 0; j <= 9; ++j)
  31.             for (long k = j+1; k <= 9; ++k)
  32.                 put(1, i, j, k, 0);
  33.     // tìm tất cả hoán vị nhị phân có 2 chữ số
  34.     // sau đó thêm vô mảng set
  35.     //Process
  36.     a.erase(a.begin()); // xóa số 0
  37.     a.insert(1e9); // thêm số 10 mủ 9
  38.     long cnt = 0;  
  39.     for (auto i : a)
  40.         if (i > n)
  41.             break;
  42.         else
  43.             ++cnt;
  44.     cout << cnt << nln;
  45.     //Output
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment