How Many Zeroes? LightOJ - 1140
#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的更多相关文章
- 数位dp(D - How Many Zeroes? LightOJ - 1140 )
题目链接:https://cn.vjudge.net/contest/278036#problem/D 题目大意:T组测试数据,每一次输入两个数,求的是在这个区间里面,有多少个0,比如说19203包括 ...
- lightoj 1140 - How Many Zeroes?(数位dp)
Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...
- LightOJ 1140 How Many Zeroes
题意:写出一个给定区间的每个数,求出一共写了多少个零. 解法:数位DP,定义dp[len][flag][num]:len的定义为数位的长度,flag定义为前导0和没有前导0的两种状态,num定义为写的 ...
- LightOJ 1140: How Many Zeroes? (数位DP)
当前数位DP还不理解的点: 1:出口用i==0的方式 2:如何省略状态d(就是枚举下一个数的那个状态.当然枚举还是要的,怎么把空间省了) 总结: 1:此类DP,考虑转移的时候,应当同时考虑查询时候的情 ...
- LightOJ 1140 How Many Zeroes? (数位DP)
题意:统计在给定区间内0的数量. 析:数位DP,dp[i][j] 表示前 i 位 有 j 个0,注意前导0. 代码如下: #pragma comment(linker, "/STACK:10 ...
- LightOJ 1140 计数/数位DP 入门
题意: 给出a,b求区间a,b内写下过多少个零 题解:计数问题一般都会牵扯到数位DP,DP我写的少,这道当作入门了,DFS写法有固定的模板可套用 dp[p][count] 代表在p位 且前面出现过co ...
- LightOJ - 1140 统计0的数位 数位DP
注意以下几点: 搜索维度非约束条件的都要记录,否则大概率出错,比如_0 st参数传递和_0的互相影响要分辨清楚 num==-1就要返回0而不是1 #include<iostream> #i ...
- Lightoj 1140(数位DP)
求一个区间内的数含有多少个0. dp[len][pre]表示长度为len的数,含有pre个0. 需要加一个标记,来表示前缀是否为0(可以是一串连续的0),如果前缀一直为0,就一直搜,如果前缀不为0,就 ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
随机推荐
- 增长中的时间序列存储(Scaling Time Series Data Storage) - Part I
本文摘译自 Netflix TechBlog : Scaling Time Series Data Storage - Part I 重点:扩容.缓存.冷热分区.分块. 时序数据 - 会员观看历史 N ...
- sed memo 2
配置文件注释过滤 示例文件 [user_00@txyun test]$ cat sed_test # comment aaaaaaaaaaa bbbb #comment cccc dddd fffo ...
- pytorch中tensorboardX的用法
在代码中改好存储Log的路径 命令行中输入 tensorboard --logdir /home/huihua/NewDisk1/PycharmProjects/pytorch-deeplab-xce ...
- Mac下安装SecureCRT并激活
今天花了好长的时间终于把SecureCRT安装成功了 现在分享给大家 安装的步骤, 希望对大家用帮助 Mac下的SecureCRT需要破解才能使用 所以有些费劲的.. 先下载SecureCRT和破解文 ...
- Vue学习3:计算属性computed与监听器
下面是计算属性相关代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- [批处理]使用IncrediBuilder加速自动化测试过程
背景 1.目前单机全部跑完一次测试的时间大概是5个小时 2.7个虚拟机进行分布式执行的时间大概为3.5小时(包含复制.收集日志的时间) 预期 期望通过IncrediBuilder的虚拟进程的功能在单机 ...
- WebForm文件上传
用 FileUpload控件进行上传文件. <asp:FileUpload ID="FileUpload1" runat="server" /> ...
- liunx驱动----USB驱动
现象:把usb设备接入电脑 1.Windows发现设备 2.跳出一个对话框提示安装驱动程序 问1:既然没有驱动程序,为什么了够知道是什么驱动了?? 答1:Windows里面已经有了usb总线驱动程序, ...
- ldap认证jupyter notebook
虽然jupyter hub是支持ldap的,见ldapauthenticator: 但是登录成功后似乎要以登录用户名启动notebook,而登录用户在服务器上不存在,于是500了: 在服务器上通过pa ...
- SNMP理解
前两天项目要求一个附加功能,远程监视服务器的运行状况,要定期监视指定端口,指定业务,还包括服务器的磁盘空间,内存,CPU使用率等等.这头俩事还好说,ping和telnet也就搞定了,实在不行就开个so ...