POJ2282 The Counting Problem】的更多相关文章

题意 Language:DefaultEspañol The Counting Problem Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5070 Accepted: 2590 Description Given two integers a and b, we write the numbers between a and b, inclusive, in a list. Your task is to calcula…
用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…
/** 题目:UVA 1640 The Counting Problem UVA1640 链接:https://vjudge.net/problem/UVA-1640 题意:求[a,b]或者[b,a]区间内0~9在里面各个数的数位上出现的总次数. 思路:数位dp: dp[leadzero][i][j][k]表示前面是否选过非0数,即i长度之后可以第一个出现0,而不是前导0,长度为i,前面出现j,k次,j出现的次数. */ #include<iostream> #include<cstri…
The Counting Problem Description 求 [L,R]内每个数码出现的次数. Input Format 若干行,一行两个正整数 L 和 R. 最后一行 L=R=0,表示输入结束. Output Format 若干行,对于每个询问做出回答,每行 10 个整数,依次表示 0 至 9 出现的次数. 输入的最后一行不属于询问,因此不必对此做出回答. Sample Input 1 10 114 514 233 666 19260421 19260817 19190504 1989…
The Counting Problem 询问区间\([a,b]\)中\(1\sim 9\)出现的次数,0 < a, b < 100000000. 解 显然为数位递推,考虑试填法,现在关键是求出方案数,于是设\(A[i]\)表示i位以内数字中0出现的次数,不含前导0,\(B[i]\)为i位数字中\(0\sim 9\)出现的次数,可以含前导0,不难有(其中\(base[i]=10^i\)),显然有 \[B[i]=10\times B[i-1]+base[i-1]\] \[A[i]=A[i-1]+…
Description Given two integers a and b, we write the numbers between a and b, inclusive, in a list. Your task is to calculate the number of occurrences of each digit. For example, if a = 1024 and b = 1032, the list will be 1024 1025 1026 1027 1028 10…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4515 题意: 给出整数a.b,统计a和b(包含a和b)之间的整数中,数字0,1,2,3,4,5,6,7,8,9分别出现了多少次.1≤a,b≤1e8. 分析: 解决这类题目的第一步一般都是:令f(n,d)表示0-n中数字d出现的次数,则所求的就是f(b,d)-f(a-1,d).例如,…
https://vjudge.net/problem/UVA-1640 题意:统计区间[l,r]中0——9的出现次数 数位DP 注意删除前导0 #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ],a[],dp[][],bit[]; int dfs(int dep,int ty,bool lim,int k) { if(!de…
[题目链接] http://poj.org/problem?id=2282 [算法] 数位DP [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #inclu…
题意: 统计[a, b]或[b, a]中0~9这些数字各出现多少次. 分析: 这道题可以和UVa 11361比较来看. 同样是利用这样一个“模板”,进行区间的分块,加速运算. 因为这里没有前导0,所以分块的时候要多分几种情况. 以2345为例,这是一个四位数,首先要计算一下所有的一位数.两位数以及三位数各个数字出现的个数. 对应的模板分别为n,n*,n**,其中n代表非零数字,*代表任意数字. 考虑这样一个长为l的模板****(l个*),这样的数共10l个,而且各个数字都是等频率出现,所以每个数…