题意:写出一个给定区间的每个数,求出一共写了多少个零。

解法:数位DP,定义dp[len][flag][num]:len的定义为数位的长度,flag定义为前导0和没有前导0的两种状态,num定义为写的满足条件的0的个数。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
#define exp 1e-10
#define PI 3.141592654
using namespace std;
typedef long long LL;
LL digit[];
LL dp[][][];
LL dfs(LL len,bool flag,LL p,LL p2,bool fp)
{
if (!len)
{
if (!flag)
return p2-p;
else return ;
}
if (!fp && dp[len][flag][p2-p]!=-) return dp[len][flag][p2-p];
LL ret=;
LL fpmax= fp ? digit[len] : ;
for (LL i= ;i<=fpmax ;i++)
{
bool ok= i== ? true : false;
LL temp;
if (i==) temp= ; else temp= ;
ret += dfs(len-,flag&&ok,flag?p+temp:p ,p2+temp,fp&&i==fpmax);
}
if (!fp) return dp[len][flag][p2-p]=ret;
return ret;
}
LL f(LL n)
{
if (n==-) return -;
if (n==) return ;
LL len=;
while (n)
{
digit[++len]=n%;
n /= ;
}
return dfs(len,true,,,true);
}
int main()
{
int t;
int ncase=;
cin>>t;
while (t--)
{
LL a,b;
scanf("%lld%lld",&a,&b);
memset(dp,-,sizeof(dp));
printf("Case %d: %lld\n",ncase++,f(b)-f(a-));
}
return ;
}

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

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

    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. How Many Zeroes? LightOJ - 1140

    #include<stdio.h> #include<string.h> #include<math.h> #include<time.h> #incl ...

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

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

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

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

  6. Light oj 1140 How Many Zeroes?

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

  7. light oj 1140 - How Many Zeroes? 数位DP

    思路:dp[i][j]:表示第i位数,j表示是否有0. 代码如下: #include<iostream> #include<stdio.h> #include<algor ...

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

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

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

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

随机推荐

  1. winform 自定义控件以及委托事件的使用

    源代码:http://files.cnblogs.com/files/qtiger/%E8%AE%A1%E7%AE%97%E5%99%A8%E5%AE%89%E8%A3%85%E5%8C%85%E4% ...

  2. apache2下部署node.js应用程序

    版本:apache2.2+node.js(v.10.25) 系统环境:ubuntu 12.04(LTS) 32位 因为有些模块并没有开启 所以需要使用以下命令开启该模块 windows下则直接在htt ...

  3. C#连接mysql实例

    using System; using System.Configuration; using MySql.Data.MySqlClient; /// <summary> /// Test ...

  4. Ksoap2 获取webservice返回值的getResponse() 出现的问题

    今天写了一个判断记录重复的webservcie 返回布尔类型 // 判断序列号在数据库是否重复 public static boolean isSerialNumExist(String serial ...

  5. Kafka入门学习(一)

    ====常用开源分布式消息系统 *集群:多台机器组成的系统叫集群. *ActiveMQ还是支持JMS的一种消息中间件. *阿里巴巴metaq,rocketmq都有kafka的影子. *kafka的动态 ...

  6. STL之迭代器

    容器支持的迭代器类型  STL Container  Type of Iterators Supported   vector  random access iterators 元素严格有序(类似数组 ...

  7. 006-python基础-条件判断与循环

    一.条件判断 场景一.用户登陆验证 # 提示输入用户名和密码 # 验证用户名和密码 # 如果错误,则输出用户名或密码错误 # 如果成功,则输出 欢迎,XXX! #!/usr/bin/env pytho ...

  8. asp.net web.config 经典模式和集成模式相关配置

    <?xml version="1.0"?> <configuration> <!--IIS经典模式下使用--> <system.web&g ...

  9. Labview实现脉波调制( PAM )

    Labview实现脉波调制( PAM ) 根据定义为脉冲振幅调制 生成一个正弦信号,得到其幅值输入给一个方波信号的幅值 这个等价于一个方波信号和一个正弦信号相乘 得到的PAM信号通过观察其频率可以发现 ...

  10. .gitignore无效,不能过滤某些文件

    利用.gitignore过滤文件,如编译过程中的中间文件,等等,这些文件不需要被追踪管理. 现象: 在.gitignore添加file1文件,以过滤该文件,但是通过git status查看仍显示fil ...