洛谷P2602 [ZJOI2010]数字计数 题解
题目描述

输入格式

输出格式

输入输出样例
输入样例
1 99
输出样例
9 20 20 20 20 20 20 20 20 20
说明/提示
数据规模与约定

分析
很裸的一道数位DP的板子
定义f[当前枚举到的数位][当前数位之前的答案][枚举的数字]
其它的套板子就可以了,要注意一下前缀0的判断
代码
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
ll f[][][],num[];
ll a,b;
ll asd(ll now,ll tot,ll ask,ll jud,ll zer){
if(now<){
return tot;
}
if(f[now][tot][ask]!=- && jud== &&(ask || !zer)){
return f[now][tot][ask];
}
ll mmax=;
if(jud==) mmax=num[now];
ll anss=;
for(ll i=;i<=mmax;i++){
anss+=asd(now-,tot+( (i==ask) & (!zer || i)),ask,jud&(i==mmax),zer&(i==));
}
if(!jud && (ask || !zer)) f[now][tot][ask]=anss;
return anss;
}
ll solve(ll xx,ll ask){
ll cnt=;
memset(num,,sizeof(num));
while(xx){
ll aa=xx%;
num[cnt++]=aa;
xx/=;
}
return asd(cnt-,,ask,,);
}
int main(){
memset(f,-,sizeof(f));
scanf("%lld%lld",&a,&b);
for(ll i=;i<=;i++){
ll ans=solve(b,i)-solve(a-,i);
printf("%lld ",ans);
}
printf("\n");
return ;
}
洛谷P2602 [ZJOI2010]数字计数 题解的更多相关文章
- 洛谷P2602 [ZJOI2010]数字计数 题解 数位DP
题目链接:https://www.luogu.com.cn/problem/P2602 题目大意: 计算区间 \([L,R]\) 范围内 \(0 \sim 9\) 各出现了多少次? 解题思路: 使用 ...
- 洛谷 P2602 [ZJOI2010]数字计数
洛谷 第一次找规律A了一道紫题,写篇博客纪念一下. 这题很明显是数位dp,但是身为蒟蒻我不会呀,于是就像分块打表水过去. 数据范围是\(10^{12}\),我就\(10^6\)一百万一百万的打表. 于 ...
- 洛谷P2602 [ZJOI2010]数字计数(数位dp)
数字计数 题目传送门 解题思路 用\(dp[i][j][k]\)来表示长度为\(i\)且以\(j\)为开头的数里\(k\)出现的次数. 则转移方程式为:\(dp[i][j][k] += \sum_{t ...
- [洛谷P2602][ZJOI2010]数字计数
题目大意:求区间$[l,r]$中数字$0\sim9$出现个数 题解:数位$DP$ 卡点:无 C++ Code: #include <cstdio> #include <iostrea ...
- 洛谷P2602 [ZJOI2010] 数字计数 (数位DP)
白嫖的一道省选题...... 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 usin ...
- BZOJ1833或洛谷2602 [ZJOI2010]数字计数
BZOJ原题链接 洛谷原题链接 又是套记搜模板的时候.. 对\(0\sim 9\)单独统计. 定义\(f[pos][sum]\),即枚举到第\(pos\)位,前面枚举的所有位上是当前要统计的数的个数之 ...
- 【洛谷P2602】数字计数
题目大意:求 [a,b] 中 0-9 分别出现了多少次. 题解:看数据范围应该是一个数位dp. 在 dfs 框架中维护当前的位置和到当前位置一共出现了多少个 \(x,x\in [0,9]\).因此,用 ...
- P2602 [ZJOI2010]数字计数&P1239 计数器&P4999 烦人的数学作业
P2602 [ZJOI2010]数字计数 题解 DFS 恶心的数位DP 对于这道题,我们可以一个数字一个数字的求 也就是分别统计区间 [ L , R ] 内部数字 i 出现的次数 (0<=i&l ...
- P2602 [ZJOI2010]数字计数(递推)
P2602 [ZJOI2010]数字计数 思路: 首先考虑含有前导0的情况,可以发现在相同的\(i\)位数中,每个数的出现次数都是相等的.所以我们可以设\(f(i)\)为\(i\)位数每个数的出现次数 ...
随机推荐
- STL中的string
string常用函数 1.构造函数 string(const char *s); //用c字符串s初始化 string(int n,char c); //用n个字符c初始化 string类还支持默认构 ...
- Error reporting for dbus
D-Bus 1.13.14 目录 Detailed Description Function Documentation ◆ dbus_error_free() ◆ dbus_error_has_na ...
- Python报错:SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
运行python文件的时候报错: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2 ...
- 关于thinkphp5下URL附加参数,无法获取到(?参数)
nginx 配置问题: 修改配置后:
- @atcoder - AGC003F@ Fraction of Fractal
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 H*W 黑白格图,保证黑格四连通. 定义分形如下:0 ...
- Codeforces Round #561 (Div. 2) A Tale of Two Lands 【二分】
A Tale of Two Lands 题目链接(点击) The legend of the foundation of Vectorland talks of two integers xx and ...
- (十)深入理解maven构建生命周期和各种plugin插件
链接:https://blog.csdn.net/zhaojianting/article/details/80321488
- SpringMVC框架搭建流程(完整详细版)
SpringMVC框架搭建流程 开发过程 1)配置DispatcherServlet前端控制器 2)开发处理具体业务逻辑的Handler(@Controller. @RequestMapping) 3 ...
- VSCode + WSL 2 + Ruby环境搭建详解
vscode配置ruby开发环境 vscode近年来发展迅速,几乎在3年之间就抢占了原来vim.sublime text的很多份额,犹记得在2015-2016年的时候,ruby推荐的开发环境基本上都是 ...
- 关于GridView的横向合并数据信息
此为asp.net 运行展示: 前端代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehin ...