HDU-4507 数位DP 记录一个毒瘤错误orz

题意:求区间【L,R】满足以下性质:(1)数位中没有7,(2)数位和不被7整除,(3)数字本身不被7整除  的所有数字的平方和

先记录一个毒瘤错误。。。感觉自己好不会设状态啊。数位dp的状态自己都不知道是不是对的能不能转移QAQ。

错误代码:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define LL long long
 5 using namespace std;
 6 
 7 int a[20];
 8 LL dp[20][200][10];
 9 const int mod = 1e9+7;
10 
11 LL dfs(int pos, int sum, LL n, bool lim){
12     if (pos == -1) {
13         if (sum % 7 == 0) return 0;
14         if (n % 7 == 0) return 0;
15         return (n%mod)*(n%mod)%mod;
16     }
17     if (!lim && dp[pos][sum][n%7] != -1) return dp[pos][sum][n%7];
18     LL ans = 0;
19     int r = lim ? a[pos] : 9;
20     for (int i = 0; i <= r; i++){
21         if (i == 7) continue;
22         ans = (ans + dfs(pos-1, sum+i, n*10+i, lim && i == a[pos]) + mod) % mod;
23     }
24     if (!lim) dp[pos][sum][n%7] = ans;
25     return ans;
26 }
27 
28 LL solve(LL x){
29     int pos = 0;
30     while (x){
31         a[pos++] = x%10;
32         x /= 10;
33     }
34     return dfs(pos-1, 0, 0, 1);
35 }
36 
37 int main(){
38     int t;
39     LL a, b;
40     scanf("%d", &t);
41     memset(dp, -1, sizeof dp);
42     while (t--){
43         scanf("%lld%lld", &a, &b);
44         printf("%lld\n", (solve(b)-solve(a-1)+mod)%mod);
45     }
46     return 0;
47 }
View Code

AC之后放正确代码qwq

猜你喜欢

转载自www.cnblogs.com/QAQorz/p/9363608.html