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

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…
题意:统计l-r中每种数字出现的次数 很明显的数位dp问题,虽然有更简洁的做法但某人已经习惯了数位dp的风格所以还是选择扬长避短吧(说白了就是菜啊) 从高位向低位走,设状态$(u,lim,ze)$表示当前走到了第几位,是否有上限,是否有前导零的状态,则问题转化成了求所有转移路径中经过的所有数字的数量统计问题. 设$f[u][lim][ze]$为从状态$(u,lim,ze)$向后走能到达的状态总数,$g[u][lim][ze][i]$为状态$(u,lim,ze)$及其向后走能到达的所有状态中数字$…
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…
题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位dp了.只是貌似正解是o(n)的算法.可是n才 1000.用o(n^2)的复杂度也是够的. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long…
题目链接:http://hihocoder.com/problemset/problem/1259 题目大意:g(t)=(f(i)%k=t)的f(i)的个数 求所有的(0-k-1)的g(i)的异或总值 思路:首先推出公式3*f(n)*f(2n+1)=f(2n)*(1+3f(n)) 3f(n)和3f(n)+1相邻的两个数肯定是互质的 所以解出f(2n)=3*f(n) f(2n+1)=3*f(n)+1 相当于是n表示成2进制但是每位的权值为3 然后就是数位dp的过程了 dp[k][i][j] k表示…
链接:https://ac.nowcoder.com/acm/contest/554/G Now we have a function f(x): int f ( int x ) {     if ( x == 0 ) return 0;     return f ( x / 10 ) + x % 10; } For a given interval [A, B] (1 <= A <= B <= 10^9), calculate how many integer x that mod f…
题意 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…
题目大意: 称一个数x的各个数位之和为f(x) 求区间L R之间 有多少个数x%f(x)==0 #include <bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f #define LL long long #define inc(i,j,k) for(int i=j;i<=k;i++) #define dec(i,j,k) for(int i=j;i>=k;i--) #define gcd(i,j) __gcd(…
题意:求[a,b]区间内的数字中正序对的个数. 具体思路参考: https://blog.csdn.net/weixin_43135318/article/details/88061396 https://www.cnblogs.com/asdfsag/p/11278519.html 在此基础上维护一下每个状态中大于每个数字的数字出现的次数即可. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ll bi…