#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. std::vector<bool> 在 auto 推断下的返回值是 bool & 引用

    转自: https://www.cnblogs.com/hustxujinkang/p/5218148.html //////////// std::vector<bool> featur ...

  2. python的高级数组之稀疏矩阵

    稀疏矩阵的定义: 具有少量非零项的矩阵(在矩阵中,若数值0的元素数目远多于非0元素的数目,并且非0元素分布没有规律时,)则称该矩阵为稀疏矩阵:相反,为稠密矩阵.非零元素的总数比上矩阵所有元素的总数为矩 ...

  3. G面经Prepare: Print Zigzag Matrix

    For instance, give row = 4, col = 5, print matrix in zigzag order like: [1, 8, 9, 16, 17] [2, 7, 10, ...

  4. java消息队列--ActiveMQ

    1.下载安装ActiveMQ ActiveMQ官网下载地址:http://activemq.apache.org/download.html ActiveMQ 提供了Windows 和Linux.Un ...

  5. map-有序 multimap-可重复 unordered_map-无序

    #include <iostream> #include <vector> #include <map> #include <unordered_map> ...

  6. RESTful API 最佳实践----转载阮一峰

    文章地址http://www.ruanyifeng.com/blog/2018/10/restful-api-best-practices.html

  7. GALV_maptravel研究分析(2)

    本节地图:Gov's Mansion,Campsite,Yourmansion ++++++++++++++++++++华丽丽的分割线+++++++++++++++++++++++++++++++++ ...

  8. delphi 判断端口(Port)是否被占用(转载)

    function IsPortUsed(aPort: Integer): Boolean; var _vSock: TSocket; _vWSAData: TWSAData; _vAddrIn: TS ...

  9. 【转】数据处理常用的sql语句整理

    一下语句都是基于 mysql数据库 查询是否使用索引 explain  select * FROM t_table1; 结果列的含义: table:此次查询操作是关联哪张数据表 type:连接查询操作 ...

  10. Django model 字段类型及选项解析---转载

    model field 类型1.AutoField() 自增的IntegerField,通常不用自己设置,若没有设置主键,Django会自动添加它为主键字段,Django会自动给每张表添加一个自增的p ...