数位DP--HDU4722(Good Numbers)
来源:互联网 发布:jquery 数组转字符串 编辑:程序博客网 时间:2024/06/05 21:52
Good Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 901 Accepted Submission(s): 336
Problem Description
If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number.
You are required to count the number of good numbers in the range from A to B, inclusive.
You are required to count the number of good numbers in the range from A to B, inclusive.
Input
The first line has a number T (T <= 10000) , indicating the number of test cases.
Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 1018).
Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 1018).
Output
For test case X, output "Case #X: " first, then output the number of good numbers in a single line.
Sample Input
2
1 10
1 20
1 10
1 20
Sample Output
Case #1: 0
Case #2: 1
Hint
The answer maybe very large, we recommend you to use long long instead of int.
/********************************************************************* Problem:4722--Good Number* source:HDU* 分析:记忆化搜索部分,pre表示前面各位数字之和对该数取模的结果* author:sgx* date:2013/09/15* PS:出现了十几次奇葩错误之后终于艰难AC。。。。*********************************************************************/#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define LL __int64const int maxn=25;LL dp[maxn][12];LL digit[maxn];LL l,r;LL DFS(int pos,int pre,bool limit){ if(pos==-1) return pre==0; if(!limit&&dp[pos][pre]!=-1) return dp[pos][pre]; LL res=0,end=limit?digit[pos]:9; for(int i=0;i<=end;i++) { int new_pre=(pre+i)%10; res+=DFS(pos-1,new_pre,limit&&i==end); } if(!limit) dp[pos][pre]=res; return res;}LL solve(LL n)//传参没传好,WA十几次;{ int len=0; while(n) { digit[len++]=n%10; n/=10; } return DFS(len-1,0,true);}int main(){ int test; scanf("%d",&test); for(int ii=1;ii<=test;ii++) { memset(dp,-1,sizeof(dp)); scanf("%I64d%I64d",&l,&r); printf("Case #%d: %I64d\n",ii,solve(r)-solve(l-1)); } return 0;}
- HDU4722:Good Numbers(数位DP)
- hdu4722 Good Numbers (数位DP)
- 数位DP--HDU4722(Good Numbers)
- hdu4722 Good Numbers 数位dp
- hdu4722 Good Numbers(数位dp)
- hdu4722 Good Numbers(数位dp)
- HDU4722 Good Numbers (基础数位dp)
- 初探数位DP(hdu4722 Good Numbers以及zzuli OJ 有问题的里程表(2)
- Good Numbers (数位DP)
- hdu4722 Good Numbers
- 【HDU4722】【Good Numbers】
- HDU4722-Good Numbers
- HDU4722 数位DP
- hdu4722(数位dp)
- hdu4722数位DP
- HDU4722(数位dp)
- HDU4722数位DP
- hdu4722 Good Numbers 规律题
- 树形DP专辑-ZOJ3201(Tree of Tree)
- XDCTF2013线上赛exploit关(二)
- linux系统的组成——The composition of the Linux system
- 一元多项式相加
- 在Windows8下MDK(uVision4)无法使用?!
- 数位DP--HDU4722(Good Numbers)
- TJU Change
- 软件工程—结构化分析设计
- Linux串口—struct termios结构体
- autoit3 试用
- Android获取设备ID、型号及其它信息
- OCP-1Z0-053-V12.02-598题
- 用多线程模式来做作业和洗衣服(有史以来最通俗最简单的多线程例子,不多说也不解释)
- C#获取 URL参数