SPOJ BALNUM ★(位压缩状态+数位DP)】的更多相关文章

题意 求区间[A,B]上的平衡数个数.平衡数是这样的数:在数的各个位上,奇数数字出现偶数次,偶数数字出现奇数次. 思路 很明显我们需要记录每一位出现的次数.分别记录是不明智的,而我们又只需要记录奇数次或者偶数次即可.所以我们可以用一个<=1024的数state表示0~9这10个数字出现的次数奇偶性,当奇数出现偶数次则相应位为1,当偶数出现奇数次相应位为1,最后判断是不是1023.但是这样它的初试状态不好确定.很明显初始时我们需要把state赋值成1010101010,即682(0次算偶次).但是…
题目:http://www.spoj.com/problems/BALNUM/en/ 题意:找出区间[A, B]内所有奇数字出现次数为偶数,偶数字出现次数为计数的数的个数. 分析: 明显的数位dp题,首先,只有3种状态(0:没出现过, 1:数字出现奇数次, 2:数字出现偶数次),所以, 0~9 出现的次数就可以用3进制表示,最大的数就是 310 ,那么我们就可以把1019 哈希到310 内了.其中,我们可以假设: (0:30  ,1:31 , 2:32 , .... , 9: 39 ) 当第一次…
思路: 把0~9的状态用3进制表示,数据量3^10 代码: #include<cstdio> #include<map> #include<set> #include<queue> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<iostream> #include<algorithm&…
Balanced Numbers Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced number if: 1)      Every even digit appears an odd number of times in its decimal representation 2)      Every odd digit app…
链接: https://vjudge.net/problem/SPOJ-BALNUM 题意: Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced number if: 1) Every even digit appears an odd number of times in its decimal representation 2)…
题目链接:http://www.spoj.com/problems/BALNUM/en/ 题意:问你在[A,B]的闭区间内有几个满足要求的数,要求为每个出现的奇数个数为偶数个,每个出现的偶数个数为奇数个. 显然dfs很好想到dfs(int len , int even[] , int odd[] , int flag , int first) even表示前len位出现偶数的总状态 , odd表示前len位出现奇数的总状态,first表示是否为首位(特判全为0的结果) 但是这样写dfs dp不好…
hdu 4734:把限制值化为数组形式,逐位求解 hdu 4507:类似于上题,其中求平方和的方法很妙 SPOJ  BALNUM Balanced Numbers:经典数位dp,注意两点,1,不要把前导0的0记录进去了,如09,实际应该是9,0没有出现过.2,要注意二进制记录法,因为要在状态和数字之间相互转换(双向),好像无法哈希... hdu 3562:想要知道前后两个选择的数,多开一维就可以啦 hdu 3709:注意分析,其实不算是难题…
SORTBIT - Sorted bit squence no tags Let's consider the 32 bit representation of all integers i from m up to n inclusive (m ≤ i ≤ n; m × n ≥ 0, -2^31 ≤ m ≤ n ≤ 2^31-1). Note that a negative number is represented in 32 bit Additional Code. That is the…
        ID Origin Title   62 / 175 Problem A CodeForces 55D Beautiful numbers   30 / 84 Problem B HDU 4352 XHXJ's LIS   108 / 195 Problem C HDU 2089 不要62   89 / 222 Problem D HDU 3555 Bomb   59 / 107 Problem E POJ 3252 Round Numbers   47 / 75 Problem…
传送门 题意:给出$N$个范围在$[0,2^k-1]$的整数,定义位运算$NAND$为位运算$AND$的逆运算,求$[L,R]$中有多少数能成为若干个前面给出的整数.若干括号和$NAND$运算组成的表达式的结果(每一个数在一个表达式中可以出现多次). OI生涯第一道数位DP 可以使用$NAND$表示所有基本位运算(这个可以手玩出来qwq),那么$NAND$像基本位运算一样会有一个性质:如果所有给出的整数中第$i$位和第$j$位相同,那么最后的结果的第$i$位与第$j$位也一定相同,而不满足这个条…