https://vjudge.net/problem/UVA-1640

题意:统计区间[l,r]中0——9的出现次数

数位DP

注意删除前导0

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int ans[],a[],dp[][],bit[];
int dfs(int dep,int ty,bool lim,int k)
{
if(!dep) return ty;
if(!lim && dp[dep][ty]!=-) return dp[dep][ty];
int ans=,up= lim ? a[dep] : ;
for(int i=;i<=up;i++)
{
if(i==k) ans+=dfs(dep-,ty+,lim && i==up,k);
else ans+=dfs(dep-,ty,lim && i==up,k);
}
if(!lim) dp[dep][ty]=ans;
return ans;
}
int main()
{
int l,r;
bit[]=;
for(int i=;i<=;i++) bit[i]=bit[i-]*;
while(scanf("%d%d",&l,&r)!=EOF)
{
if(!l) return ;
if(l>r) swap(l,r);
memset(ans,,sizeof(ans));
a[]=;
while(r) a[++a[]]=r%,r/=;
for(int i=;i<=;i++)
{
memset(dp,-,sizeof(dp));
ans[i]=dfs(a[],,,i);
}
l--; if(!l) ans[]--;
int tmp=a[];
a[]=;
while(l) a[++a[]]=l%,l/=;
for(int i=;i<=;i++)
{
memset(dp,-,sizeof(dp));
ans[i]-=dfs(a[],,,i);
}
while(tmp!=a[]) ans[]-=bit[--tmp];
printf("%d",ans[]);
for(int i=;i<=;i++) printf(" %d",ans[i]);
printf("\n");
}
}

UVA 1640 The Counting Problem的更多相关文章

  1. UVA 1640 The Counting Problem UVA1640 求[a,b]或者[b,a]区间内0~9在里面各个数的数位上出现的总次数。

    /** 题目:UVA 1640 The Counting Problem UVA1640 链接:https://vjudge.net/problem/UVA-1640 题意:求[a,b]或者[b,a] ...

  2. UVa 1640 - The Counting Problem(数论)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. UVa 1640 The Counting Problem (数学,区间计数)

    题意:给定两个数m, n,求从 m 到 n 中0-9数字各出现了多少次. 析:看起来挺简单的,其实并不好做,因为有容易想乱了.主要思路应该是这样的,分区间计数,先从个位进行计,一步一步的计算过来.都从 ...

  4. UVA.1640.The Counting Problem / BZOJ.1833.[ZJOI2010]数字计数(数位DP)

    题目链接 \(Description\) 求\([l,r]\)中\(0,1,\cdots,9\)每个数字出现的次数(十进制表示). \(Solution\) 对每位分别DP.注意考虑前导0: 在最后统 ...

  5. UVA 1640 The Counting Problem(按位dp)

    题意:给你整数a.b,问你[a,b]间每个数字分解成单个数字后,0.1.2.3.4.5.6.7.8.9,分别有多少个 题解:首先找到[0,b]与[0,a-1]进行区间减法,接着就只是求[0,x] 对于 ...

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

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

  7. uva 11401 Triangle Counting

    // uva 11401 Triangle Counting // // 题目大意: // // 求n范围内,任意选三个不同的数,能组成三角形的个数 // // 解题方法: // // 我们设三角巷的 ...

  8. UVa 101 The Blocks Problem Vector基本操作

    UVa 101 The Blocks Problem 一道纯模拟题 The Problem The problem is to parse a series of commands that inst ...

  9. UVa 1225 Digit Counting --- 水题

    UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...

随机推荐

  1. maven 教程二 深入

    一:编写POM <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w ...

  2. js学习之正则表达式

    js学习之正则表达式 正则表达式(英语:Regular Expression,在代码中常简写为regex.regexp或RE)使用单个字符串来描述.匹配一系列符合某个句法规则的字符串搜索模式 一:语法 ...

  3. 使用 letter-space 后文字不能居中解决

    letter-space:2em; text-align: center; 使用letter-space后和上面的字体对比明显没有居中: 选定元素后发现,每个字后面都被加了2em,不是不能居中而是因为 ...

  4. 常用web资源

    ip相关 新浪:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=220.181.38.110 (不带参数本机) ...

  5. block知识总结

    一.block在内存中存在的形式 1.当把block句法写在函数或者方法外面时,系统会在静态数据区分配一块内存区域给block对象.这片区域在程序执行期会一直存在. 2.当block句法写在函数或者方 ...

  6. TCP系列22—重传—12、Forward Retransmit

    一.概述 forward retransmit相关的内容在RFC6675中有描述,可以参考RFC6675 section 4中NextSeg ()的定义.forward retransmit中文名可以 ...

  7. 一个比较典型的WMI查询

    Get-WmiObject win32_bios -ComputerName server1, server2 | Format-Table ` @{n='Hostname';e={$_.__serv ...

  8. 在Centos中,大容量,且读写频繁的目录

    1./根目录 2./usr目录 3./home目录 4./var目录 5./Swap目录     比较特殊,只要物理内存没使用完,就不会被启用 以上为鸟哥的linuxPDF中的学习心得

  9. AMH面板命令操作大全

    LNMP面板 - AMH 命令使用nginx篇 » SSH Nginx1) 有步骤提示操作: ssh执行命令: amh nginx然后选择对应选项进行操作. 2) 或直接操作: 启动Nginx: am ...

  10. BZOJ 1015 星球大战(并查集)

    正着不好搞,考虑倒着搞.倒着搞就是一个并查集. # include <cstdio> # include <cstring> # include <cstdlib> ...