Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<set>
- #define long long long
- #define nln '\n'
- using namespace std;
- set<int> a;
- void put(long i, long n, long x, long y, long sum)
- {
- if (i > n){
- a.insert(sum);
- return;
- }
- put(i+1, n, x, y, sum*10+x);
- put(i+1, n, x, y, sum*10+y);
- }
- int main()
- {
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- //freopen("somayman.inp", "r", stdin);
- long n;
- cin >> n;
- //Input
- for (long i = 1; i <= 9; ++i)
- for (long j = 0; j <= 9; ++j)
- for (long k = j+1; k <= 9; ++k)
- put(1, i, j, k, 0);
- // tìm tất cả hoán vị nhị phân có 2 chữ số
- // sau đó thêm vô mảng set
- //Process
- a.erase(a.begin()); // xóa số 0
- a.insert(1e9); // thêm số 10 mủ 9
- long cnt = 0;
- for (auto i : a)
- if (i > n)
- break;
- else
- ++cnt;
- cout << cnt << nln;
- //Output
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment