#include<stdio.h>
#include<string.h>
#include<math.h>
#include<time.h>
#include<iostream>
#include<ctype.h>
#include<map>
#include<set>
#include<string>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
using namespace std;
#define LL long long
LL dp[][],num[];
LL dfs(int pos,int iszero,int st,int limit)//pow为数位,iszero判断是否为0,st上一个状态初始为0,limit是否达到上限
{
if(pos<)
{
if(iszero)
return ;
else
return st;
}
if(!limit&&!iszero&&dp[pos][st]!=-)
return dp[pos][st];
LL ans=;
int len=limit?num[pos]:;
for(int i=;i<=len;i++)
{
if(iszero)
ans+=dfs(pos-,i==,,limit&&i==len);
else
ans+=dfs(pos-,,st+(i==),limit&&i==len);
}
if(!limit&&!iszero)
dp[pos][st]=ans;
return ans; }
LL sv(LL a)
{
int len=;
memset(dp,-,sizeof(dp));
memset(num,,sizeof(num));
while(a)
{
num[len++]=a%;
a/=;
}
return dfs(len-,,,);
}
int main()
{
LL m,n;
while(~scanf("%lld%lld",&n,&m))
{
// LL ee=sv(m)-sv(n-1);
printf("%lld\n",sv(m)-sv(n-));
} }

How Many Zeroes? LightOJ - 1140的更多相关文章

  1. 数位dp(D - How Many Zeroes? LightOJ - 1140 )

    题目链接:https://cn.vjudge.net/contest/278036#problem/D 题目大意:T组测试数据,每一次输入两个数,求的是在这个区间里面,有多少个0,比如说19203包括 ...

  2. lightoj 1140 - How Many Zeroes?(数位dp)

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

  3. LightOJ 1140 How Many Zeroes

    题意:写出一个给定区间的每个数,求出一共写了多少个零. 解法:数位DP,定义dp[len][flag][num]:len的定义为数位的长度,flag定义为前导0和没有前导0的两种状态,num定义为写的 ...

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

    当前数位DP还不理解的点: 1:出口用i==0的方式 2:如何省略状态d(就是枚举下一个数的那个状态.当然枚举还是要的,怎么把空间省了) 总结: 1:此类DP,考虑转移的时候,应当同时考虑查询时候的情 ...

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

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

  6. LightOJ 1140 计数/数位DP 入门

    题意: 给出a,b求区间a,b内写下过多少个零 题解:计数问题一般都会牵扯到数位DP,DP我写的少,这道当作入门了,DFS写法有固定的模板可套用 dp[p][count] 代表在p位 且前面出现过co ...

  7. LightOJ - 1140 统计0的数位 数位DP

    注意以下几点: 搜索维度非约束条件的都要记录,否则大概率出错,比如_0 st参数传递和_0的互相影响要分辨清楚 num==-1就要返回0而不是1 #include<iostream> #i ...

  8. Lightoj 1140(数位DP)

    求一个区间内的数含有多少个0. dp[len][pre]表示长度为len的数,含有pre个0. 需要加一个标记,来表示前缀是否为0(可以是一串连续的0),如果前缀一直为0,就一直搜,如果前缀不为0,就 ...

  9. LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)

    http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS     M ...

随机推荐

  1. 20.C# 创建自己的泛型类型

    1.定义泛型类 可以使用以下语法创建泛型类,T可以是任意符合C#标识符命名规范的任意标识符 class MyGenericClass<T> { //.... } 泛型类可以包含任意多个类型 ...

  2. 一分钟学会Xmind

  3. windows10上安装mysql(详细步骤)

    2016年09月06日 08:09:34 阅读数:46198 环境:windwos 10(1511) 64bit.mysql 5.7.14 时间:2016年9月5日 一.下载mysql 1. 在浏览器 ...

  4. 能否显示pdf?

    <iframe src='http://km.shengaitcm.com/ADC/_layouts/15/WopiFrame.aspx?sourcedoc=%2FADC%2FDocLib16% ...

  5. 2.第一个python 程序

    第一个python程序 一..python程序的编写步骤 1.创建  xxx.py文件(文件名不要中文) 文件名要以py为扩展名,因为导入的时候其他扩展名会报错.如果不导入的情况可以不限制扩展名. 2 ...

  6. windows之电脑开机出现 this product is covered by one or more of the following prtents

    电脑开机出现 this product is covered by one or more of the following prtents 有次意外断电后就每次都出现这个提示,然后要等检查完才能进入 ...

  7. 百度站内搜索https不可用切换api搜索,加上谷歌api站内搜索

    google推https几年了,百度开始宣传全面https,但是,百度站内搜索 自己的服务却不走https,接口报错.百度分享也是. 然后采用http://search.zhoulujun.cn/cs ...

  8. Django框架详细介绍---认证系统

    在web开发中通常设计网站的登录认证.注册等功能,Django恰好内置了功能完善的用户认证系统 1.auth模块 from django.contrib import auth 模块源码 import ...

  9. 关于webpack官网的学习

    webpack,从名词上,"web pack",大概可以看出是一个网页打包工具,其实它具有打包.压缩.解析编译的功能. 使用(配置webpack.config.js) entry: ...

  10. C#-----线程安全的ConcurrentQueue<T>队列

     ConcurrentQueue<T>队列是一个高效的线程安全的队列,是.Net Framework 4.0,System.Collections.Concurrent命名空间下的一个数据 ...