Good Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 428    Accepted Submission(s): 149

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.
 
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 <= 10
18).
 
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

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<iomanip>
#define INF 99999999
using namespace std; const int MAX=22;
__int64 dp[MAX][10];//分别代表长度为i位数和mod 10为j的个数
int digit[MAX]; void digit_dp(){//计算每长度为i为的数mod 10 == 0的个数
dp[0][0]=1;
for(int i=1;i<MAX;++i){
for(int j=0;j<10;++j){
for(int k=0;k<10;++k){
dp[i][j]+=dp[i-1][(j-k+10)%10];
}
}
}
} __int64 calculate(__int64 n){
int size=0,last=0;
__int64 sum=0;
while(n)digit[++size]=n%10,n/=10;
for(int i=size;i>=1;--i){
for(int j=0;j<digit[i];++j){
sum+=dp[i-1][((0-j-last)%10+10)%10];
}
last=(last+digit[i])%10;
}
return sum;
} int main(){
digit_dp();
int t,num=0;
__int64 a,b;
scanf("%d",&t);
while(t--){
scanf("%I64d%I64d",&a,&b);
printf("Case #%d: %I64d\n",++num,calculate(b+1)-calculate(a));
}
return 0;
}

hdu4722之简单数位dp的更多相关文章

  1. HDU 2089 简单数位dp

    1.HDU 2089  不要62    简单数位dp 2.总结:看了题解才敲出来的,还是好弱.. #include<iostream> #include<cstring> #i ...

  2. windy数(简单数位DP)

    1026: [SCOI2009]windy数 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 6306  Solved: 2810[Submit][Sta ...

  3. 简单数位DP

    https://cn.vjudge.net/problem/HDU-4722 懒得写看,代码注释吧;主要存板子 #include <cstdio> #include <cstring ...

  4. [DP]数位DP总结

     数位DP总结 By Wine93 2013.7 1.学习链接 [数位DP] Step by Step   http://blog.csdn.net/dslovemz/article/details/ ...

  5. POJ 3252 Round Number(数位DP)

    Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6983   Accepted: 2384 Des ...

  6. 数位dp 的简单入门

    时间紧张,就不讲那么详细了. 之前一直被深搜代码误解,以为数位dp 其实就是记忆化深搜...(虽说爆搜确实很舒服而且还好想) 但是后来发现数位dp 的标准格式其实是 预处理 + dp ...... 数 ...

  7. 数位dp 简单入门

    推荐博客 推荐博客 数位dp是一种计数用的dp,一般就是要统计一个区间[le,ri]内满足一些条件数的个数.所谓数位dp,字面意思就是在数位上进行dp咯.数位还算是比较好听的名字,数位的含义:一个数有 ...

  8. cojs 简单的数位DP 题解报告

    首先这道题真的是个数位DP 我们考虑所有的限制: 首先第六个限制和第二个限制是重复的,保留第二个限制即可 第五个限制在转移中可以判断,不用放在状态里 对于第一个限制,我们可以增加一维表示余数即可 对于 ...

  9. [Swust OJ 648]--简单字典(数位dp)

    题目链接:http://acm.swust.edu.cn/problem/0648/ Time limit(ms): 1000 Memory limit(kb): 65535   有这样一本字典,它每 ...

随机推荐

  1. JavaScript 导学推荐

    基本开始js学习的时候,可能会觉得很混乱,一开始都是从一些简单的表单验证还有拷贝别人效果代码,然后再慢慢去深入了解.我是觉得js是需要一定语言编程基础,我是觉得随着深入,JS的里面实在不算太好理解,个 ...

  2. Hbase split的过程以及解发条件

    一.Split触发条件   1.  有任一一个Hfile的大小超过默认值10G时,都会进行split    2.  达到这个值不在拆分,默认为int_max,不进行拆分       3.compact ...

  3. MVC3 Razor @RenderSection

    Mvc3的Razor视图引擎还提供了@RenderSection @RenderSection在母版页中占个位,然后让使用此母版页的子页自己去呈现他们的Section. 在母版页_Layout.csh ...

  4. 基于visual Studio2013解决C语言竞赛题之0205位数求和

     题目

  5. zkw费用流模版

    /************************************************************** Problem: 3876 User: wangck1998 Langu ...

  6. (收藏)KMP算法的前缀next数组最通俗的解释

    我们在一个母字符串中查找一个子字符串有很多方法.KMP是一种最常见的改进算法,它可以在匹配过程中失配的情况下,有效地多往后面跳几个字符,加快匹配速度. 当然我们可以看到这个算法针对的是子串有对称属性, ...

  7. UVA 103 Stacking Boxes (dp + DAG上的最长路径 + 记忆化搜索)

     Stacking Boxes  Background Some concepts in Mathematics and Computer Science are simple in one or t ...

  8. window下如何搭建linux环境

    1.使用虚拟机 使用VMware虚拟机,下载linux内核系统,加载运行. 2.cygwin 安装cygwin,设置环境变量. 第二种方法还是比较简便的.优先考虑.

  9. 转化为用欧几里得算法判断互质的问题D - Wolf and Rabbit

    Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...

  10. codeblock快捷键

    一款开源的C/C++ IDE(集成开发环境),基于wxWidgets GUI体系,跨平台支持. 从别处粘贴的,方便以后看,啦啦啦…… 编辑器 快捷键 功能 Ctrl+Z 恢复上一次操作 Ctrl+Sh ...