思路: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. simplexml_load_string 解析gb2312编码的xml

    <?php header('Content-type:text/html;charset=UTF-8'); $url = 'http://www.xxx.com/text.xml'; $cont ...

  2. 归并排序 & 计数排序 & 基数排序 & 冒泡排序 & 选择排序 ----> 内部排序性能比较

    2.3 归并排序 接口定义: int merge(void* data, int esize, int lpos, int dpos, int rpos, int (*compare)(const v ...

  3. Android HttpClient GET或者POST请求基本使用方法(转)

    在Android开发中我们经常会用到网络连接功能与服务器进行数据的交互,为此Android的SDK提供了Apache的HttpClient来方便我们使用各种Http服务.这里只介绍如何使用HttpCl ...

  4. P1297: [SCOI2009]迷路

    首先知道,如果没有路径长度的要求,且给定的邻接矩阵只有0和1表示通与不通的话,从S->E走N次的方案数就是这个矩阵自乘N次后的(S,E)的数值.这样的话只需要快速幂+矩阵乘法即可过关. (转载请 ...

  5. angularjs resources

    http://tutorials.jenkov.com/angularjs/watch-digest-apply.html http://angular-tips.com/blog/2013/08/w ...

  6. Android BLE API: GATT Notification not received

    When setting the value to the descriptor instead of putting descriptor.setValue(BluetoothGattDescrip ...

  7. Notes of the scrum meeting(12.7)

    meeting time:18:30~19:10p.m.,December 7th,2013 meeting place:3号公寓一层 attendees: 顾育豪                   ...

  8. PSP0表格

    一 项目计划日志 周活动总结表 姓名:陆宇                                                                         日期:3.1 ...

  9. Kibana4学习<三>

    discover 功能 Discover 标签页用于交互式探索你的数据.你可以访问到匹配得上你选择的索引模式的每个索引的每条记录.你可以提交搜索请求,过滤搜索结果,然后查看文档数据.你还可以看到匹配搜 ...

  10. C语言面向对象风格编程

    前言 本文略谈C面向对象风格编程,如何使用过程式语言去模拟面向对象的特性?C面向对象的方式和形式很多,不一而足,本文的代码形式是模拟部分C++面向对象关键词并赋予其特性,这种方式对于初级程序员比较好理 ...