UVa 11361 Investigating Div-Sum Property / 数位DP
来源:互联网 发布:阿里云搜索 编辑:程序博客网 时间:2024/05/16 15:58
先上代码 以后再说
#include <cstdio>#include <cstring>const int maxn = 110;int dp[maxn][maxn][maxn];int ok(int x, int k){if(x < 10)return x / k;int a = x;int b = 1;int l = 0;while(a){l++;a /= 10;b *= 10;}b /= 10;//printf("%d %d\n", a, b);int ret = 0;int m1 = 0, m2 = 0;int d = 1;while(l--){int c = x / b;//printf("%d\n", c);if(l == 0){for(int j = 0; j <= c; j++)if(((k-j-m1)%k+k)%k == 0 && ((k-j-m2)%k+k)%k == 0)ret++;break;}for(int j = 0; j < c; j++)ret += dp[l-1][((k-j-m1)%k+k)%k][((k-j*b-m2)%k+k)%k];//printf("%d\n", c);m1 += c;m2 += c*b;x -= c*b;b /= 10;}return ret-1;}int main(){int T;int a, b, k;scanf("%d", &T);while(T--){scanf("%d %d %d", &a, &b, &k);if(k > 82){printf("0\n");continue;}int c = a, d = 1;memset(dp, 0, sizeof(dp));for(int i = 0; i < 10; i++)dp[0][i%k][i%k]++;for(int i = 1; i <= 10; i++){d *= 10;if(d * 10 > b){//printf("%d\n", d);break;}for(int m1 = 0; m1 < k; m1++){for(int m2 = 0; m2 < k; m2++){for(int j = 0; j < 10; j++){dp[i][((m1+j)%k+k)%k][((m2+j*d)%k+k)%k] += dp[i-1][m1][m2];}}}}printf("%d\n", ok(b,k)-ok(a-1,k));}return 0;}
0 0
- UVa 11361 Investigating Div-Sum Property / 数位DP
- UVA 11361 - Investigating Div-Sum Property(数位DP)
- uva 11361 - Investigating Div-Sum Property(数位dp)
- UVa 11361 - Investigating Div-Sum Property (数位DP)
- UVA 11361 Investigating Div-Sum Property(数位DP)
- uva 11361 Investigating Div-Sum Property 数位dp
- uva 11361 Investigating Div-Sum Property 数位DP
- Uva 11361Investigating Div-Sum Property(数位DP)
- UVA 11361 - Investigating Div-Sum Property-数位DP
- UVa 11361 Investigating Div-Sum Property (数位DP)
- uva 11361 Investigating Div-Sum Property
- Investigating Div-Sum Property Uva 11361
- UVA - 11361 Investigating Div-Sum Property
- uva 11361 Investigating Div-Sum Property
- UVa 11361 Investigating Div-Sum Property
- uva 11361 Investigating Div-Sum Property
- UVA 11361Investigating Div-Sum Property
- UVa 11361Investigating Div-Sum Property
- 我为自己代言
- OCP-1Z0-053-200题-199题-159
- 【Lua】ElJudge 001 Max of Integers
- 栈
- 分区格式--MBR与GPT
- UVa 11361 Investigating Div-Sum Property / 数位DP
- 新年新气象
- 你好大家!这是我第一博客文章 (或者是第一在这里这个网站的)
- Shell学习(4)——shell变量(三)
- Ajax返回XML数据
- uva 657 The die is cast
- 用python来进行html页面解析
- 关于IO包装流中的两个read方法
- Microsoft NLayerApp案例理论与实践【应用层】