首页 > 代码库 > HDU 4722 数位dp
HDU 4722 数位dp
Good Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4753 Accepted Submission(s): 1511
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
Sample Output
Case #1: 0
Case #2: 1
Hint
The answer maybe very large, we recommend you to use long long instead of int.
Source
2013 ACM/ICPC Asia Regional Online —— Warmup2
题意:对一个数字 每一位求和%10==0 问一个区间内有多少个这类数字
题解:模板题
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <algorithm> 6 #include <stack> 7 #include <queue> 8 #include <cmath> 9 #include <map>10 #define ll __int6411 #define dazhi 214748364712 #define bug() printf("!!!!!!!")13 #define M 20000514 using namespace std;15 int t;16 ll l,r;17 ll bit[20];18 ll dp[100][15];19 ll functi(int pos ,int flag,int m)20 {21 if(pos==0) return (m==0);22 if(flag&&dp[pos][m]!=-1) return dp[pos][m];23 ll x=flag?9:bit[pos];24 ll ans=0;25 for(ll i=0;i<=x;i++)26 ans+=functi(pos-1,flag||i<x,(m+i)%10);27 if(flag) dp[pos][m]=ans;28 return ans;29 }30 ll fun(ll num)31 {32 int len=0;33 memset(bit,0,sizeof(bit));34 while(num)35 {36 bit[++len]=num%10;37 num/=10;38 }39 return functi(len,0,0);40 }41 int main()42 {43 while(scanf("%d",&t)!=EOF)44 {45 memset(dp,-1,sizeof(dp));46 for(int i=1;i<=t;i++)47 {48 scanf("%I64d %I64d",&l,&r);49 printf("Case #%d: %I64d\n",i,fun(r)-fun(l-1));50 }51 }52 return 0;53 }
HDU 4722 数位dp
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。