Advertisement
Dmaxiya

数字串个数 参考代码

Mar 28th, 2025
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 10000 + 100;
  6. const LL MOD = 1000000007;
  7. LL dp[maxn][4];
  8.  
  9. LL fastPow(LL res, LL n) {
  10.     LL ans;
  11.     for (ans = 1; n != 0; n >>= 1) {
  12.         if ((n & 1) == 1) {
  13.             ans = ans * res % MOD;
  14.         }
  15.         res = res * res % MOD;
  16.     }
  17.     return ans;
  18. }
  19.  
  20. int main() {
  21. #ifdef ExRoc
  22.     freopen("test.txt", "r", stdin);
  23. #endif // ExRoc
  24.     ios::sync_with_stdio(false);
  25.  
  26.     dp[0][0] = 1;
  27.     for (int i = 1; i <= 10000; ++i) {
  28.         dp[i][0] = dp[i - 1][0] * 7 % MOD;
  29.         dp[i][1] = (dp[i - 1][0] * 1 + dp[i - 1][1] * 8 % MOD) % MOD;
  30.         dp[i][2] = (dp[i - 1][0] + dp[i - 1][2] * 8 % MOD) % MOD;
  31.         dp[i][3] = (dp[i - 1][1] + dp[i - 1][2] + dp[i - 1][3] * 9) % MOD;
  32.     }
  33.     cout << dp[10000][3] << endl;
  34.  
  35.     cout << ((fastPow(9, 10000) - 2 * fastPow(8, 10000) + fastPow(7, 10000)) % MOD + MOD) % MOD << endl;
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement