用dp[pos][val][cnt]表示状态,pos是数位,val是当前统计的数字,cnt是目前统计的目标数字的出现次数

注意状态的转移过程,统计数字0时前导0的影响。

 1 #include<cstdio>
2 #include<cstring>
3 #include<algorithm>
4 using namespace std;
5 typedef long long LL;
6 int dig[15],pos;
7 LL dp[15][10][15],ans[2][10];
8
9 LL dfs(int pos,int val,int cnt,bool lead,bool limit){
10 if(pos==0) return cnt;
11 if(!limit&&!lead&&dp[pos][val][cnt]!=-1) return dp[pos][val][cnt];
12 int len=limit?dig[pos]:9,t=0;
13 LL ans=0;
14 for(int i=0;i<=len;i++){
15 if(val!=i) t=cnt;
16 else{
17 if(lead&&val==0) t=0;
18 else t=cnt+1;
19 }
20 ans+=dfs(pos-1,val,t,lead&&i==0,limit&&i==len);
21 }
22 if(!limit&&!lead) dp[pos][val][cnt]=ans;
23 return ans;
24 }
25
26 void solve(LL x,int idx){
27 if(x==0) return ;
28 int pos=0;
29 while(x){
30 dig[++pos]=x%10;
31 x/=10;
32 }
33 for(int i=0;i<10;i++)//对每一个数字分别求解
34 ans[idx][i]=dfs(pos,i,0,1,1);
35 }
36
37 int main(){
38 memset(dp,-1,sizeof(dp));
39 LL a,b;
40 while(~scanf("%lld%lld",&a,&b),a+b){
41 if(a>b) swap(a,b);
42 memset(ans,0,sizeof(ans));
43 solve(a-1,0),solve(b,1);
44 for(int i=0;i<10;i++)
45 printf("%lld ",ans[1][i]-ans[0][i]);
46 printf("\n");
47 }
48 return 0;
49 }

POJ2282 The Counting Problem(数位DP)的更多相关文章

  1. 『The Counting Problem 数位dp』

    The Counting Problem Description 求 [L,R]内每个数码出现的次数. Input Format 若干行,一行两个正整数 L 和 R. 最后一行 L=R=0,表示输入结 ...

  2. UVA - 1640 The Counting Problem (数位dp)

    题意:统计l-r中每种数字出现的次数 很明显的数位dp问题,虽然有更简洁的做法但某人已经习惯了数位dp的风格所以还是选择扬长避短吧(说白了就是菜啊) 从高位向低位走,设状态$(u,lim,ze)$表示 ...

  3. POJ2282:The Counting Problem(数位DP)

    Description Given two integers a and b, we write the numbers between a and b, inclusive, in a list. ...

  4. hdu 5106 Bits Problem(数位dp)

    题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...

  5. hiho1259 A Math Problem (数位dp)

    题目链接:http://hihocoder.com/problemset/problem/1259 题目大意:g(t)=(f(i)%k=t)的f(i)的个数 求所有的(0-k-1)的g(i)的异或总值 ...

  6. 哈尔滨工程大学ACM预热赛 G题 A hard problem(数位dp)

    链接:https://ac.nowcoder.com/acm/contest/554/G Now we have a function f(x): int f ( int x ) {     if ( ...

  7. POJ2282 The Counting Problem

    题意 Language:DefaultEspañol The Counting Problem Time Limit: 3000MS Memory Limit: 65536K Total Submis ...

  8. nowcoder A hard problem /// 数位DP

    题目大意: 称一个数x的各个数位之和为f(x) 求区间L R之间 有多少个数x%f(x)==0 #include <bits/stdc++.h> using namespace std; ...

  9. Gym - 102040B Counting Inversion (数位dp)

    题意:求[a,b]区间内的数字中正序对的个数. 具体思路参考: https://blog.csdn.net/weixin_43135318/article/details/88061396 https ...

随机推荐

  1. SkyWalking分布式系统应用程序性能监控工具-中

    其他功能 性能剖析 在系统性能监控方法上,Skywalking 提出了代码级性能剖析这种在线诊断方法.这种方法基于一个高级语言编程模型共性,即使再复杂的系统,再复杂的业务逻辑,都是基于线程去进行执行的 ...

  2. 关于又拍云免费cdn全网加速服务的长期评测(各种踩坑)

    原文转载自「刘悦的技术博客」 ( https://v3u.cn/a_id_128 ) 妇孺皆知,前端优化中最重要的优化手段之一就是cdn加速,所谓cdn加速就是采用更多的缓存服务器(CDN边缘节点), ...

  3. 基于Python3(Autosub)以及Ffmpeg配合GoogleTranslation(谷歌)为你的影片实现双语版字幕(逐字稿)

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_169 为影片加字幕其实是一件非常耗费时间的事情,尤其是对于打字慢的朋友来说.当然不光为影片加字幕,在其他领域,类似的逐字稿也是工作 ...

  4. 产品 | GreatSQL,打造更好的MGR生态

    欢迎来到 GreatSQL社区分享的MySQL技术文章,如有疑问或想学习的内容,可以在下方评论区留言,看到后会进行解答 GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 用 ...

  5. C#/VB.NET 将PDF转为PDF/X-1a:2001

    PDF/X-1a是一种PDF文件规范标准,在制作.使用PDF以及印刷时所需要遵循的技术条件,属于PDF/X-1标准下的一个子标准. PDF/X-1标准有由CGATS于1999年制定的PDF/X-1:1 ...

  6. C 语言 时间函数使用技巧(汇总)

    time.h 头文件 是 C 语言中 有关 时间的函数所储存的头文件 #include <time.h> 在介绍时间函数用法之前,我们首先要了解在 time.h 头文件中已经声明了的一个结 ...

  7. Clickhouse基准测试实践

    1.概述 本篇博客将对MySQL.InfluxDB.Clickhouse在写入时间.聚合查询时间.磁盘使用等方面的性能指标来进行比较. 2.内容 比较的数据集,是使用的Clickhouse官网提供的6 ...

  8. mac M1通过homebrew安装python3报错Error: Command failed with exit 128: git

    fatal: not in a git directoryError: Command failed with exit 128: git 只需要运行 git config --global --ad ...

  9. Qt 创建按钮动画

    1 封装自定义按钮 myPushBttton 2 构造函数 (默认图片,按下后显示图片) 3 测试开始按钮 4 开始制作特效 5 zoom1 向下弹跳 6 zoom2 向上弹跳 代码如下 main.h ...

  10. E - Road Reduction

    E - Road Reduction (atcoder.jp) 题意:一棵树n个点,m条路, di表示1-i的距离,问怎么选择边可以使得d2+...dn最短. 题解: 很明显,就是直接套最短路板子,判 ...