Link:

BZOJ 1833 传送门

Solution:

比较明显的数位DP

先预处理出1~9和包括前导0的0的个数:$pre[i]=pre[i-1]*10+10^{digit-1}$

(可以分为首位和其它位来考虑问题)

求$(L,R)$的个数,可以用$(1,R)-(1,L-1)$差分来做

在求$(1,K)$时,我们先根据预处理的值算出$[0,999....99]$的值(不受边界影响)

接下来从最高位开始尽可能增加$10^n$,直到达到边界后再开始增加$10^{n-1}$

每次对于前面已确定的部分暴力算,而后面不确定的、可任意取值的直接用$pre[i]$统计

Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll res[],pre[]; void split(ll x,ll pos){while(x) res[x%]+=pos,x/=;}
void Digital_DP(ll x,int flag)
{
int i,j;ll pos=,now;
for(i=;pos<x;i++)//对[0,99..99]进行统计
{
for(j=;j<=;j++)
res[j]+=pre[i-]**flag;
for(j=;j<=;j++)
res[j]+=pos/*flag;
pos*=;
} now=pos/=;i--;
while(now<x)
{
while(now+pos<=x)
{
ll temp=now/pos;
split(temp,pos*flag);//对已确定部分的暴力统计
for(j=;j<=;j++)//对可任意取值部分的统一计算
res[j]+=pre[i]*flag;
now+=pos;
}
pos/=;i--;
}
}
int main()
{
int i;ll a,b,pos=;
pre[]=;
for(i=;i<=;i++)
pre[i]=pre[i-]*+pos,pos*=; cin >> a >> b;
Digital_DP(b+,);Digital_DP(a,-);
for(i=;i<=;i++) cout << res[i] << " ";
}

Review:

1、对于所有i位中每个数字出现次数的预处理要积累:

$pre[i]=pre[i-1]*10+10^{digit-1}$

2、数位统计中的区间问题,考虑差分,都化为$(1,K)$的形式进行求解

3、数位DP中,特殊处理边界;数字出现次数,特殊处理前导0

最新文章

  1. jq样式方法总结
  2. php日常日志写入格式记录
  3. ado.net中,数据的批量处理
  4. 设置p标签自动换行
  5. [Bootstrap]7天深入Bootstrap(4)CSS组件
  6. STL 源码分析《1》---- list 归并排序的 迭代版本, 神奇的 STL list sort
  7. eclipse 中文乱码
  8. sqlite 对表的操作
  9. Android怎么让一个service开机自动启动
  10. 【最大团】【HDU1530】【Maximum Clique】
  11. 【Unity与23种设计模式】装饰模式(Decorator)
  12. mybatis报错:Caused by: java.lang.IllegalArgumentException: Caches collection already contains value for com.crm.dao.PaperUserMapper
  13. C# Note37: Writing unit tests with use of mocking
  14. 【ProtoBuffer】windows上安装ProtoBuffer3.1.0 (附已编译资源)
  15. Ansible工具原理一
  16. Modifying namespace in XML document programmatically
  17. 一款纯HTML+CSS+JS富文本编辑器-handyeditor
  18. week3c:个人博客作业
  19. 怎么让一个div 悬浮在另一个div上
  20. LeetCode——Find Minimum in Rotated Sorted Array

热门文章

  1. HTML5 canvas流体力学效果
  2. MySQL使用笔记(五)简单数据记录查询
  3. C语言指针大杂烩
  4. linux启动一个web项目时验证码不能出现的问题的解决
  5. sqrti128
  6. zigbee芯片 - JN5169
  7. BAT定期删除N天前的文件
  8. 封装getByClass(JS获取class的方法封装为一个函数)
  9. jquery教程-Jquery 获取标签个数 size()函数用法
  10. 在Ubuntu下安装IntelliJ IDEA