思路:dp[i][j]:表示第i位数,j表示是否有0.

代码如下:

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#define ll long long
#define pi acos(-1.0)
#define MAX 50000
using namespace std;
int bit[];
ll dp[][],p[];
ll dfs(int pos,int m,bool f)
{
if(pos==-) return !m;
if(!f&&dp[pos][m]!=-) return dp[pos][m];
ll ans=;
int e=f?bit[pos]:;
for(int i=;i<=e;i++){
if(i==&&m){
if(!(f&&i==e)) ans+=p[pos]+dfs(pos-,,);
else{
ll t=;
for(int j=pos;j>=;j--) t=t*+bit[j];
t++;
ans+=t+dfs(pos-,,);
}
}
else ans+=dfs(pos-,m||i!=,f&&i==e);
}
if(!f) dp[pos][m]=ans;
return ans;
}
ll cal(ll n)
{
if(n<) return ;
int m=;
while(n){
bit[m++]=n%;
n/=;
}
return dfs(m-,,);
}
int main(){
int t,ca=;
ll a,b;
p[]=;
memset(dp,-,sizeof(dp));
for(int i=;i<;i++) p[i]=*p[i-];
scanf("%d",&t);
while(t--){
scanf("%lld%lld",&a,&b);
printf("Case %d: %lld\n",++ca,cal(b)-cal(a-));
}
return ;
}

light oj 1140 - How Many Zeroes? 数位DP的更多相关文章

  1. Light oj 1140 How Many Zeroes?

    Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...

  2. LightOJ 1140 How Many Zeroes? (数位DP)

    题意:统计在给定区间内0的数量. 析:数位DP,dp[i][j] 表示前 i 位 有 j 个0,注意前导0. 代码如下: #pragma comment(linker, "/STACK:10 ...

  3. UVALive - 6575 Odd and Even Zeroes 数位dp+找规律

    题目链接: http://acm.hust.edu.cn/vjudge/problem/48419 Odd and Even Zeroes Time Limit: 3000MS 问题描述 In mat ...

  4. Light OJ 1140

    数位dp,需要记录前导0. 数位dp中需要注意统计0,00,000……这些数字. 数位dp的写法可以分为两类.由于我们通常采用记忆化搜索的方式进行dp,所以我们有一个记忆化数组. 一种是记忆化数组的意 ...

  5. Light OJ 1031 - Easy Game(区间DP)

    题目大意: 给你一个n,代表n个数字,现在有两个选手,选手A,B轮流有有一次机会,每个选手一次可以得到一个或者多个数字,从左侧或者右侧,但是不能同时从两边取数字,当所有的数字被取完,那么游戏结束.然后 ...

  6. Light OJ 1021 - Painful Bases(状态压缩DP)

    题目大意: 给你一个base 进制的数字,把这个数字的每一位进行全排列,问有多少个数字是可以整除k的. 题目解析: #include<cstdio> #include<cstring ...

  7. Light OJ 1004 - Monkey Banana Problem(DP)

    题目大意: 给你一菱形的数字阵,问从最上面走到最下面所能获得的最大值是多少? #include<cstdio> #include<cstring> #include<io ...

  8. Light oj 1044 - Palindrome Partitioning(区间dp)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 dp[i][j]表示i到j直接的最小回文区间个数,直接看代码 #include ...

  9. 小米oj 找小"3"(数位dp)

     找小"3" 序号:#40难度:困难时间限制:1000ms内存限制:10M 描述 给定一个奇数n,可得到一个由从1到n的所有奇数所组成的数列,求这一数列中数字3所出现的总次数.例如 ...

随机推荐

  1. poj 3641 Pseudoprime numbers

    题目连接 http://poj.org/problem?id=3641 Pseudoprime numbers Description Fermat's theorem states that for ...

  2. poj 2485 Highways

    题目连接 http://poj.org/problem?id=2485 Highways Description The island nation of Flatopia is perfectly ...

  3. Golang的Semicolons

    Semicolons The formal grammar uses semicolons ";" as terminators in a number of production ...

  4. [转]linux时间同步

    转自:http://www.jotop.com/2012/vpsinfo_0525/439.html 美国的vps大多都是国外的时间,让我们的程序总是不适应.那么如何调整linux的时间为北京时间?修 ...

  5. Python运行Google App Engineer时出现的UnicodeDecodeError错误解决方案

    #Python运行Google App Engineer时出现的UnicodeDecodeError错误解决方案   ##问题描述 使用Python2.7.x运行GAE时有时会报这个错误 ```py ...

  6. 元音字母A的发音规则

    摘抄自百度文库 A/a的发音比较复杂,归纳起来有10种情况: 一.在重读开音节中读[ei]. 例如: plane [plein]  radio [ˈreidiəu] wake [weik]  pape ...

  7. [shell练习]——awk练习题

    1. sed和awk有什么区别? (1)awk:按列(域)操作:sed:按行操作(2)awk:文本处理语言,适合对文本进行抽取处理:sed:非交互式的编辑器,适合对文本进行编辑 2. awk要处理域的 ...

  8. [LAMP]【转载】——PHP7.0的安装

    ***原文链接:http://my.oschina.net/sallency/blog/541287 php编译过程报错解决可参考:http://www.cnblogs.com/z-ping/arch ...

  9. C# 把引用的dll嵌入到exe文件中

    当发布的程序有引用其它dll, 又只想发布一个exe时就需要把dll打包到exe 当然有多种方法可以打包, 比如微软的ILMerge,混淆器附带的打包... 用代码打包的实现方式也有很好,本文只是其中 ...

  10. mongodb修改器

    mongodb修改器 转载自:http://blog.csdn.net/mcpang/article/details/7752736 mongodb修改器(\(inc/\)set/\(unset/\) ...