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. 微信开放平台 获取 component_verify_ticket

    <?php /** * @author zhaozhuobin * @date:2016-06=07 * */ namespace common\components;use DOMDocume ...

  2. 使用JS进行pc端、手机端判断

     <script type="text/javascript">            (function(){                var ua = nav ...

  3. asp.net 一般处理程序小优化

    使用asp.net mvc习惯了,最近项目中又开始使用asp.net,有大量的ajax方法调用,之前有两种方法来处理: Switch case :方法少还行,如果很多,就太蛋疼了,而且方法堆在一块,也 ...

  4. js触屏事件

    js的左右滑动触屏事件,主要有三个事件:touchstart,touchmove,touchend.这三个事件最重要的属性是 pageX和 pageY,表示X,Y坐标. touchstart在触摸开始 ...

  5. Xamarin.Android开发实践(四)

    原文:Xamarin.Android开发实践(四) Xamarin.Android下获取与解析JSON 一.新建项目 1.新建一个Android项目,并命名为为NetJsonList 2.右击引用,选 ...

  6. Embedded Linux Primer----嵌入式Linux基础教程--2.4节--嵌入式Linux发行版

    嵌入式Linux发行版 究竟什么是Linux发行版?在Linux内核引导之后,它期望找到并挂载根文件系统.当一个匹配的根文件系统已经挂载上,启动脚本开始运行大量程序和系统要求的工具.这些程序经常调用其 ...

  7. 从数据库中,绑定JQuery Accordion控件---Repeater control

    http://aspsnippets.com/Articles/jQuery-Accordion-example-in-ASPNet-using-C-and-VBNet.aspx 1. 添加JQuer ...

  8. 【Eclipse】调试java程序的九个技巧

    本文转自[半夜乱弹琴],原文地址:http://www.cnblogs.com/lingiu/p/3802391.html 九个技巧: 逻辑结构 条件debug 异常断点 单步过滤 跳到帧 Inspe ...

  9. Oracle同义词 synonyms

    Oracle中的同义词: 总结:简单的一句话,Oracle中不同用户的表一般都只能够自己的所属的用户可以用,如果不想通过授权的方式授权给其他用户使用,那么创建表的时候在表名的前面加上 synonyms ...

  10. JVM -- 类加载

    学习自周志明老师的<深入理解Java虚拟机>第二版 类的加载时机 如上图所示: 类从被加载到虚拟机内存中开始,直到卸载出内存为止,它的整个生命周期包括了: 加载.验证.准备.解析.初始化. ...