Codeforces 981 D.Bookshelves(数位DP)】的更多相关文章

Codeforces 981 D.Bookshelves 题目大意: 给n个数,将这n个数分为k段,(n,k<=50)分别对每一段求和,再将每个求和的结果做与运算(&).求最终结果的最大值. 思路: 将答案ans二进制表示,按位枚举,从最高位i开始,检查ans|(1<<i)是否能够得到,如果能,则ans|=1<<i,向低位继续枚举:不能,就直接继续向低位枚举. 检查 ans|(1<<i)能否得到:每次用DP的方式寻找,dp[i][j]表示将前i个数分为j段…
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if…
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…
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if…
题意:求[L,R](1<=L<=R<=9e18)区间中所有能被自己数位上的非零数整除的数的个数 分析:丛数据量可以分析出是用数位dp求解,区间个数可以转化为sum(R)-sum(L-1)前缀和相减的形式.如果一个数能被所有位上数的最小公倍数(lcm)整除,便是符合要求的数. 但是直接传递一个数n的话,dp数组肯定开不下.那么怎么让其传递的值更小呢. 先了解一个等式: sum%(x*n)%x == sum%x 可以将一个数枚举到第pos位之前的值视作sum,x是所有位上数的lcm.那么我们…
链接: https://vjudge.net/problem/CodeForces-55D 题意: 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…
题意:找到[a, b]符合下列要求的数的个数. 1.该数字能被m整除 2.该数字奇数位全不为d,偶数位全为d 分析: 1.dp[当前的位数][截止到当前位所形成的数对m取余的结果][当前数位上的数字是否到达了上限] 2.对于第三维的上限,例如一个数字是54362,那么如果前四位是5436,那么前四位都到达了上限,第五位可以从0枚举所有可能,例如如果第五位是1,那么就没到达上限,如果是6就到达了上限,简而言之,就是个匹配的问题. 需要注意的是,上限不是指第二位数字只能是0~4,第三位数字只能是0~…
题目大意: 求  1(m)到n直接有多少个数字x满足 x可以整出这个数字的每一位上的数字 思路: 整除每一位.只需要整除每一位的lcm即可 但是数字太大,dp状态怎么表示呢 发现 1~9的LCM 是2520 ....也就是说只要对这个数mod2520 剩下的余数能整除lcm就可以整除了.. 计数的时候还有一个技巧,具体见注释 此外这个题还卡常数了,预处理lcm才过了.. 代码如下: #include <iostream> #include <stdio.h> #include<…
题目链接 一个数, 他的所有位上的数都可以被这个数整除, 求出范围内满足条件的数的个数. dp[i][j][k], i表示第i位, j表示前几位的lcm是几, k表示这个数mod2520, 2520是1-9之间数的lcm. 然后这样数组就要开成20*2520*2520, 太大了, 所以我们将lcm离散, 因为1-9的lcm根本没有那么多的数, 实际上只有48个. 这题好难想... #include<bits/stdc++.h> using namespace std; #define mem1…
题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Volodya is an odd boy and his taste is strange as well. It seems to him…