rembocoder

Untitled

Apr 13th, 2023
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int int64_t
  6.  
  7. const int inf = 2e18;
  8. const int mod = 1e9 + 7;
  9.  
  10. int F[10];
  11. int f[10];
  12. int ans = 0;
  13. int fact[20];
  14.  
  15. void rec(int i) {
  16.     if (i == 10) {
  17.         int sum = 0;
  18.         for (int j = 0; j < 10; j++) {
  19.             sum += f[j];
  20.         }
  21.         int cur = fact[sum];
  22.         for (int j = 0; j < 10; j++) {
  23.             cur /= fact[f[j]];
  24.         }
  25.         ans += cur;
  26.         if (f[0] > 0) {
  27.             cur = fact[sum - 1];
  28.             f[0]--;
  29.             for (int j = 0; j < 10; j++) {
  30.                 cur /= fact[f[j]];
  31.             }
  32.             f[0]++;
  33.             ans -= cur;
  34.         }
  35.         return;
  36.     }
  37.     if (F[i] == 0) {
  38.         rec(i + 1);
  39.         return;
  40.     }
  41.     for (int j = 1; j <= F[i]; j++) {
  42.         f[i] = j;
  43.         rec(i + 1);
  44.     }
  45. }
  46.  
  47. int32_t main() {
  48.     ios_base::sync_with_stdio(0);
  49.     cin.tie(0); cout.tie(0);
  50.     fact[0] = 1;
  51.     for (int i = 1; i < 20; i++) {
  52.         fact[i] = fact[i - 1] * i;
  53.     }
  54.     int n;
  55.     cin >> n;
  56.     while (n) {
  57.         F[n % 10]++;
  58.         n /= 10;
  59.     }
  60.     rec(0);
  61.     cout << ans;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment