用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. 常用的函数式接口Function接口和常用的函数式接口Function接口默认方法andThen

    常用的函数式接口Function接口 package com.yang.Test.FunctionStudy; import java.util.function.Function; /** * ja ...

  2. IO概述(概念&分类)和字节输入流+OUTputStream类&FileOutPutStream类介绍

    IO概述 什么是IO 生活中,你肯定经历过这样的场景.当你编辑一个文本文件,忘记了保存,可能文件就白白编辑了.当你的电脑上插入一个U盘,可以吧一个视频,拷贝到你的电脑硬盘里,那么数据都是在哪些设备上的 ...

  3. 哈希-hash

    一. 概念 1.引例 有线性表(1,75,324,43,1353,90,46,-  ) 目的:查找值为90的元素 常见做法: 1.通过一维数组进行遍历查找 (依次比较)( O(n) ) 2.如果关键字 ...

  4. 项目操作案例丨西门子PLC通过网关连接ACS800变频器

    本案例控制对象为炉条机.以及蒸汽的控制以及现场数据参数的显示以及报警. PLC 选用西门子 CPU,通过 ET200 IO 模块控制现场设备并监控数据.变频器采用ABB ACS800变频器,将ABB ...

  5. cmd命令行工具

    在windows下进行python开发,需要经常使用cmd命令行工具.打开命令行工具有很多种方法,最简单的就是win键+R键弹出运行窗口,然后输入cmd, 就会打开下面这样的窗口. 不同版本,可能配色 ...

  6. Apache DolphinScheduler 需要的sudo,还可以这么玩,长见识了!

    Apache DolphinScheduler(incubator)需要的sudo,还可以这么玩,长见识了! 在新一代大数据任务调度 - Apache DolphinScheduler(以下简称dol ...

  7. MySQL通配符与正则表达式

    通配符 通配符必须全文匹配时才为真,使用LIKE关键字 字符 示例 含义 _ "a_b" 任意一个字符"axb",其中x可以使任意字符,包括汉字 % " ...

  8. LuoguP4165 [SCOI2007]组队

    化式子,然后两个指针平\(A\)过去 #include <cstring> #include <cstdio> #include <algorithm> #incl ...

  9. Nodemon 如何实时监听 TypeScript 项目下的文件并热部署?

    首先你的项目要安装ts-node和nodemon: npm i -D ts-node nodemon 在package.json文件中配置运行脚本: "dev": "no ...

  10. identity4 系列————案例篇[三]

    前言 前文介绍了identity的用法,同时介绍了什么是identitySourece.apiSource.client 这几个概念,和具体案例,那么下面继续介绍案例了. 正文 这里用官网的案例,因为 ...