An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is divisibleby 3 and 12(3+7+0+2) is also divisible by 3. This property also holds for the integer 9.In this problem, we will investigate this property for…
经典数位dp!而且这好像是数位dp的套路板子……不需要讨论原来我很头疼的一些边界. 改天用这个板子重做一下原来的一些数位dp题目. http://blog.csdn.net/the_useless/article/details/53674906 题目大意: 给定a,b,k三个正整数,统计在[a,b]之间的整数n中,有多少n自身是k的倍数,且n的各个数字(十进制)之和也是k的倍数.(1⩽a⩽b⩽231) 题目分析: 这是一道典型的数位DP题. n非常大,若是直接枚举的话会超时,考虑利用加法原理计…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2346 数位DP 代码: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath> #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…
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…
题目分析: 裸的数位DP,注意细节. #include<bits/stdc++.h> using namespace std; ; int k; ][],sz[][],cnt[][]; ],hp[],num; int dfs(int now,int lst){ ) ; ; ;i<hp[now];i++){ ;j<(<<);j++){ &&i==?:(<<i)); int z = __builtin_popcount(j|pp|lst); if…
题意:AB两人分别拿一列n个数字,只能从左端或右端拿,不能同时从两端拿,可拿一个或多个,问在两人尽可能多拿的情况下,A最多比B多拿多少. 分析: 1.枚举先手拿的分界线,要么从左端拿,要么从右端拿,比较得最优解. 2.dp(i, j)---在区间(i, j)中A最多比B多拿多少. 3.tmp -= dfs(i + 1, r);//A拿了区间(l, i),B在剩下区间里尽可能拿最优 tmp是A拿的,dfs(i + 1, r)是B比A多拿的,假设dfs(i + 1, r)=y-x,y是B拿的,x是A…
题意:求一个区间内满足所有数位不同数字个数小于K的数字总和.比如:k=2   1,2,3所有数位的不同数字的个数为1满足,但是123数位上有三个不同的数字,即123不满足. 我们可以使用一个二进制的数字来记录某个数字是否已经出现,0为还没有出现,1表示该数字已经出现了.这里还需要注意前导零的干扰. #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1832 题目大意: 两个人在玩一个游戏: 给你一行n个数字,每次只能从左端或者右端取一个或多个数字. 每个人的分值就是他们各自取得的数字之和. 假设两人都足够聪明,问先手最多能比后手多多少分. 解题思路: 其实题目意思就是先手最多能得到多少分. 设dp[l][r]是取完[l,r]的…
这题和上次的通化邀请赛的那题一样,而且还是简化版本... 那题的题解      请戳这里 ... #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; #define INF 0x3f3f3f3f int dp[105][105]; int a[105]; int sum,n; int pre_sum[105],next_s…
Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description long long ans = 0; for(int i = 1; i <= n; i ++)     ans += lowbit(i) lowbit(i)的意思是将i转化成二进制数之后,仅仅保留最低位的1及其后面的0,截断前面的内容,然后再转成10…
题目大意 给出整数k和t,需要产生一个满足以下要求的第k个十六进制数 即十六进制数每一位上的数出现的次数不超过t 首先我们先这样考虑,如果给你了0~f每个数字可以使用的次数num[i],如何求长度为L且满足要求的十六进制数有多少个 dp[i][l]表示使用了前i个数字,已经将L的空位填上了l个的数有多少个 转移方程 dp[i][l] = sigma(dp[i-1][l-j]*C[len-l+j[j]) 其中j是枚举填新的数的个数,C是组合数(选出j个空位填上新数) 有了这个dp后,现在的问题就变…
ACdreamOJ 1154 Lowbit Sum (数位dp) ACM 题目地址:pid=1154" target="_blank" style="color:rgb(0,136,204); text-decoration:none">ACdreamOJ 1154 题意: long long ans = 0; for(int i = 1; i <= n; i ++) ans += lowbit(i) lowbit(i)的意思是将i转化成二进制…
An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is divisibleby 3 and 12(3+7+0+2) is also divisible by 3. This property also holds for the integer 9.In this problem, we will investigate this property for…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 题目意思:问在区间[A,B]有多少个数不仅满足自身是k的倍数,而且其各个位数上的和(十进制)也是k的倍数. 分析:数位dp 首先注意到1+9*9=82,即k最大只能是82,所以,在大于82是直接输出答案为0: dp[i][j][t]——表示从左往右递推到第i位时(后面所有位数用0填充),各个位数上的和mod k等于j,且这个数mod k等于t时的方案数 状态转移方程为dp[i][…
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3540 题目大意: 给一块长x,宽y的巧克力,和一个数组A={a1, a2, …,an},问能否经过若干次切分后,得到面积分别为a1,a2,…an的n块巧克力.每次切分只可以选择一块巧克力,将其分为两半,如下图,3×4的巧克力经过切分后,可以得到面积分别为6,3,2,1的巧克力.…
数位DP部分,不是很难.DP[i][j]前i位j个幸运数的个数.枚举写的有点搓... #include <cstdio> #include <cstring> using namespace std; #define LL __int64 #define MOD 1000000007 ][]; ],num; ]; int dfs(int pos,int pre,int bound) { int ans,i,end; ans = ; ) ; ) return dp[pos][pre]…
B. New Year and Old Property 题目连接: http://www.codeforces.com/contest/611/problem/B Description The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly on…
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…
题目链接:uva 10712 - Count the Numbers 题目大意:给出n,a.b.问说在a到b之间有多少个n. 解题思路:数位dp.dp[i][j][x][y]表示第i位为j的时候.x是否前面是相等的.y是否已经出现过n.对于n=0的情况要特殊处理前导0,写的很乱.搓死. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using nam…
题目链接: http://codeforces.com/problemset/problem/258/B B. Little Elephant and Elections time limit per test2 secondsmemory limit per test256 megabytes 问题描述 There have recently been elections in the zoo. Overall there were 7 main political parties: one…
uva 10817(数位dp) 某校有m个教师和n个求职者,需讲授s个课程(1<=s<=8, 1<=m<=20, 1<=n<=100).已知每人的工资c(10000<=c<=50000)和能教的课程集合,要求支付最少的工资使得每门课都至少有两名教师能教.在职教师不能辞退. 用两个集合,s1表示恰好有一个人教的科目集合,s2表示至少有两个人教的科目集合.设计状态\(d(i, s1, s2)\)表示考虑了后n-i个人时的最小花费.把所有人从1到n+m编号,那么m…
F. Daniel and Spring Cleaning While doing some spring cleaning, Daniel found an old calculator that he loves so much. However, it seems like it is broken. When he tries to compute 1+3 using the calculator, he gets 2 instead of 4. But when he tries co…
Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于没考虑到前导0,卡了很久.但最惨的是,由于每次求和的时候需要用到10的pos次幂,我是用提前算好的10的最高次幂,然后每次除以10往下传参.但我手贱取模了,导致每次除以10之后答案就不同余了,这个NC细节错误卡了我一小时才发现. 代码: #include<iostream> #include<…
题目传送门 B. Perfect Number time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output We consider a positive integer perfect, if and only if the sum of its digits is exactly 1010. Given a positive integ…
This is a two player game. Initially there are n integer numbers in an array and players A and B get chance to take them alternatively. Each player can take one or more numbers from the left or right end of the array but cannot take from both ends at…
D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standard input output standard output Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change h…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5587 题目大意就是初始有一个1,然后每次操作都是先在序列后面添加一个0,然后把原序列添加到0后面,然后从0到末尾,每一个都加上1. 例如:a0, a1, a2 => a0, a1, a2, 1, a0+1, a1+1, a2+1 题解中是这么说的:“ 其实Ai为i二进制中1的个数.每次变化A{k+2^i}=A{k}+1,(k<2^​i​​)不产生进位,二进制1的个数加1.然后数位dp统计前m个数二…
传送门 D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher…
题意:统计l-r中每种数字出现的次数 很明显的数位dp问题,虽然有更简洁的做法但某人已经习惯了数位dp的风格所以还是选择扬长避短吧(说白了就是菜啊) 从高位向低位走,设状态$(u,lim,ze)$表示当前走到了第几位,是否有上限,是否有前导零的状态,则问题转化成了求所有转移路径中经过的所有数字的数量统计问题. 设$f[u][lim][ze]$为从状态$(u,lim,ze)$向后走能到达的状态总数,$g[u][lim][ze][i]$为状态$(u,lim,ze)$及其向后走能到达的所有状态中数字$…