标签:using int bbb ons put const long 数位dp 幸运
输入N(1<= N <= 1000)
输出幸运号码的数量 Mod 10^9 + 7
1
9
dp[i][j] 表示表示长度为2*i 其中一半的和为j的数量,当长度为i-1的已知时,计算长度为i时,无非就是在长度i-1上加0-9 所以dp[i][j] = ∑dp[i-1][j-k] (0 ≤ k ≤ 9) 计算长度为n时去掉前导0 dp[n][j] - dp[n-1][j]
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 const int N = 1010; 5 const int mod = 1e9+7; 6 ll dp[N][N*10]; 7 int main() { 8 dp[0][0] = 1; 9 int n;cin >> n; 10 for(int i = 1; i <= n; i ++) { 11 for(int j = 0; j <= i*9; j ++) { 12 for(int k = 0; k <= 9; k ++) { 13 if(j>=k) dp[i][j] = (dp[i][j]+dp[i-1][j-k])%mod; 14 } 15 } 16 } 17 ll ans = 0; 18 for(int i = 0; i <= 9*n; i ++) { 19 ans = (ans+(dp[n][i]-dp[n-1][i])*dp[n][i])%mod; 20 } 21 cout << ans << endl; 22 return 0; 23 }
标签:using int bbb ons put const long 数位dp 幸运
原文地址:https://www.cnblogs.com/xingkongyihao/p/9568444.html