Gym - 102040B Counting Inversion (数位dp)】的更多相关文章

题意:求[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…
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…
Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86686#problem/J Description Everyone knows that in less than a month the Ice Hockey World Championship will start in Minsk. But few of the…
题意:统计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…
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description Start with an integer, N0, which is greater than 0. Let N1 be the number of ones in the binary representation of N0. So, if N0 = 27, N1 = 4. For all i > 0, let Ni be the number…
题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++.h> typedef long long ll; const int N = 70 + 5; char str[N]; ll dp[N][10][2]; int len; ll DFS(int pos, int pre, int up, int limit) { if (pos == len) { re…
Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86821#problem/B Description Little John studies numeral systems. After learning all about fixed-base systems, he became inte…
题意:给定两个数,问区间[A,B]中0~9分别出现了多少次.A,B<=10^18 题解:应该是最裸的数位dp吧..一开始没有记忆化tle了TAT 我们可以求出区间[0,B]的,再减去区间[0,A]的. 用dfs实现,记录flag(填了的位是否和边界重合),zero(当前是否还在前缀0中) #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<…
数位dp预处理之后,可以容易得到f(x),代表小于等于x的数中,有多少个不含13的.然后就能二分答案啦. #include<cstdio> #include<iostream> using namespace std; typedef unsigned long long ull; ull n; ull f[19][3]; void init() { f[0][0]=1; for(int i=1;i<=18;++i) { f[i][0]=f[i-1][0]*10-f[i-1]…