【数位DP】CF55D Beautiful numbers】的更多相关文章

Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful num…
目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM 题目描述 NIBGNAUK is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisib…
CF55D Beautiful numbers 题意 \(t(\le 10)\)次询问区间\([l,r](1\le l\le r\le 9\times 10^{18})\)中能被每一位上数整除的数的个数,0算可以整除任何数. 最开始写了个假做法,既没算0复杂度也是假的 最开始把每个模数都压进去了,后来发现只压2520就可以了 然后前两位压前\(i\)位与\(\bmod 2520\)的结果,第三位最开始压了每个数字出现集合,这样就很屑. 可以直接压数字集合的最小公倍数,仅有不到50个取值,做一个H…
题意 题目链接 Sol 看到这种题就不难想到是数位dp了. 一个很显然的性质是一个数若能整除所有位数上的数,则一定能整除他们的lcm. 根据这个条件我们不难看出我们只需要记录每个数对所有数的lcm(也就是2520)取模的结果 那么\(f[i][j][k]\)表示还有\(i\)个数要决策,之前的数模\(2520\)为\(j\),之前的数的lcm为k的方案 第三维可以预处理 #include<bits/stdc++.h> #define Pair pair<int, int> #def…
题目链接 题解 一个数能被一些数整除,那么一定被这些数的\(lcm\)整除 那么我们容易想到根据\(lcm\)设状态 我们可以发现有用的\(lcm\)只有\(48\)个 那么按照一般的数位\(dp\) 设出状态:\(f_{i,j,k,0/1}\)表示前\(i\)位,\(lcm=j\),模\(lcm\)的余数是\(k\),是否达到上界 但是这样子是无法转移的(因为新添加一个数模数可能会产生变化) 那么我们把模数统一成\(2520\) 复杂度\(O(T*L*48*2500*2)\) 其中\(L\)是…
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful…
题目链接 题意 定义一个数字\(x\)是\(beautiful\ number\)当且仅当\(x\)可以被其十进制表示下所有非\(0\)位置的数整除. 例如\(24\)是一个\(beautiful\ number\),因为他可以被\(2\)和\(4\)整除. 而\(28\)不是一个\(beautiful\ number\),因为他不能被\(8\)整除 给出两个数字\(L,R\; (1 \le L\le R \le 10^{18})\) 求出区间\([L,R]\)内有多少\(beautiful\…
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the same when its digits are reversed. In this problem you will be given two integers i j, you have to find the number of palindromic numbers between i and j…
$dp[x][p][pp]$表示第x位,当前已有数字mod 2520(1~9数字的lcm)为p,当前各位数字的lcm为pp 观察到数组太大,考虑压缩,第三维lcm最多只有9个数字,打表发现最多只有48个状态,压掉第三维即可 打表用一个状压然后set维护(广搜也可以)即可 有一个坑点:题目里似乎没有说关于0的事情(即数字里出现0)但是有人在CF上打这个比赛的时候问了出题人,碰到0不要管即可!!! 打表代码: set<int>s; inline void Make(int x){ ; ;i<…
题意:一个数,如果满足奇数的数字出现偶数次,偶数的数字出现奇数次, 就是符合的数,注比如:12313  就满足,因为1 3出现了偶数次.2出现了奇数次 思路,对于这道题,就是状态压缩加dp: 对于一个数字来说,0~9每一位,都只有3种状态量,要么从未出现,要么出现次数为奇 要么为偶,所以可以用3进制来表示,通过3进制表示出其状态,然后到pos-1的时候 判断0~9的各个状态是否符合条件即可 #include<cstdio> #include<string.h> using name…