数位DP:SPOJ KPSUM - The Sum】的更多相关文章

KPSUM - The Sum One of your friends wrote numbers 1, 2, 3, ..., N on the sheet of paper. After that he placed signs + and - between every pair of adjacent digits alternately. Now he wants to find the value of the expression he has made. Help him. For…
题意:给定x.y.为[x,y]之间有多少个数的偶数位和减去奇数位和等于一. 个位是第一位. 样例: 10=1-0=1 所以10是这种数 思路:数位dp[i][sum][ok] i位和为sum 是否含有前导0. 然后就是由于有负数 所以依据范围把0设置为100 然后最后和等于101则为所求的数. 代码: #include"cstdlib" #include"cstdio" #include"cstring" #include"cmath&…
题意 将1~N(1<=N<=10^15)写在纸上,然后在相邻的数字间交替插入+和-,求最后的结果.例如当N为12时,答案为:+1-2+3-4+5-6+7-8+9-1+0-1+1-1+2=5. 思路 花了一上午时间调BUG--必须承认SPOJ上的好题很多~每次做都有很大收获-- 我发现原来记忆化搜索的数位DP不止可以做统计,还可以做计算.我们应该把记忆化搜索形式的数位DP理解成一种处理与各位数字有关问题的一种方法,或者也可以延伸到字符串上. 我们可以把数列在纸上写一下: -0 +1 -2 +3…
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…
BIGSEQ - Sequence You are given the sequence of all K-digit binary numbers: 0, 1,..., 2K-1. You need to fully partition the sequence into M chunks. Each chunk must be a consecutive subsequence of the original sequence. Let Si (1 ≤ i ≤ M) be the total…
题目链接:http://www.spoj.com/problems/BALNUM/en/ Time limit: 0.123s Source limit: 50000B Memory limit: 1536MB Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced number if: 1)      Every even digit…
You are given two integers l l and r r (l≤r l≤r ). Your task is to calculate the sum of numbers from l l to r r (including l l and r r ) such that each number contains at most k k different digits, and print this sum modulo 998244353 998244353 . For…
题目: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 ) 当第一次…
Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于没考虑到前导0,卡了很久.但最惨的是,由于每次求和的时候需要用到10的pos次幂,我是用提前算好的10的最高次幂,然后每次除以10往下传参.但我手贱取模了,导致每次除以10之后答案就不同余了,这个NC细节错误卡了我一小时才发现. 代码: #include<iostream> #include<…
题目链接:https://codeforces.com/contest/1073/problem/E 题目大意:给定一个区间[l,r],需要求出区间[l,r]内符合数位上的不同数字个数不超过k个的数的和(并且模998244353) 例如求区间[10,50],k=1,答案为ans=(11+22+33+44)%998244353=110. Examples input Copy 10 50 2 output Copy 1230 input Copy 1 2345 10 output Copy 275…