dp
文章平均质量分 74
ccyy-
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
CF484D 把数组划分成几段,求所有段的最大值-最小值之和的最大值
In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly原创 2015-12-01 12:09:07 · 1253 阅读 · 0 评论 -
hdu5456 Matches Puzzle Game(记忆化dfs+dp)
A - B = C 可以转化成 B + C = A 题解:http://m.blog.csdn.net/blog/stl112514/48678307 http://acm.hdu.edu.cn/showproblem.php?pid=5456 #include #include #include #include #include #include #include #include转载 2015-09-24 23:31:13 · 904 阅读 · 0 评论 -
HDU 5396 Expression(区间DP,排列组合)
http://acm.hdu.edu.cn/showproblem.php?pid=5396 思路很特别。大神的详细题解:http://www.cnblogs.com/chenchengxun/p/4741439.html 对于加减法,分成左右两块的话,对于左边的某一种运算情况,都要和右边的所有情况匹配,所以【左边】*【右边的全排列】。右边同理。 特别拎出来 乘法为什么不用乘上全排列:原创 2015-11-07 12:20:57 · 443 阅读 · 0 评论 -
hdu5544 Pick The Sticks(dp)
还是得正视这场比赛了。。不说了,就放代码。 http://acm.hdu.edu.cn/showproblem.php?pid=5543 #include #include #include #include//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0}; #include//int gcd(int a,int b){return b?gcd(b,a原创 2015-11-06 13:36:17 · 1110 阅读 · 0 评论 -
foj2204 圆环没有连续7个黑或白的可能数
作为全场难度第三的题目,比赛的时候写出来了。。好高兴。。 枚举开头0的个数(1~6),算出结果*2 #include #include #include #include #define mod 2015 #define ll long long using namespace std; ll dp[100005][8][2]; int main(){ int t,cnt=0; scanf原创 2015-10-06 17:16:47 · 609 阅读 · 0 评论 -
foj2200 n个人的环取k人且任意两个人的距离不能为2的方法数
写了一晚上,思路越来越像正确的方向靠近,只不过又犯了老错误——更改思路将第三维由2改成4后居然忘了改定义数组的部分!搞得我看了半天都不明白为什么本该加成0的变量会变成1。。。吐血ing 枚举前两个数取或不取的情况,相应的对第三位开始dp,dp[i][j][k]表示已经判别到第i位时共取了j个合法的位置且i-1位和i位选取状态由k的二进制表示。注意不预处理会超时。 #include #inclu原创 2015-10-06 22:56:59 · 655 阅读 · 0 评论 -
HDU4778 Gems Fight!(记忆化搜索+博弈)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4778 题目大意:有B个包裹,里面有各种颜色的GEM,共有G个颜色。Alice和Bob轮流挑选包裹放到一个地方,如果挑选出来的同种颜色的GEM超过S个,当前回合者可以得分,每超过S个得一分。如果在回合内得分了,可以额外进行一个回合。问Alice的得分减去Bob的得分最大是多少。 #include转载 2015-10-13 22:22:12 · 773 阅读 · 0 评论 -
【51nod】1092 回文字符串
回文串是指aba、abba、cccbccc、aaaa这种左右对称的字符串。每个字符串都可以通过向中间添加一些字符,使之变为回文字符串。 例如:abbc 添加2个字符可以变为 acbbca,也可以添加3个变为 abbcbba。方案1只需要添加2个字符,是所有方案中添加字符数量最少的。 两种截然不同的思路: 1.先求出原字符串与逆序字符串的最长公共子序列(可不连续),ans=总长度-原创 2015-11-14 12:18:46 · 1493 阅读 · 0 评论 -
【codechef】Chef and Bracket-Pairs (分层dp)
Input: 11 -1 -2 9 2 -3 -4 3 4 8 8 1 Output: 12 http://www.codechef.com/problems/CHEFBR/ #include #include #include #include #include #include #include #include #include #include原创 2015-06-19 15:19:00 · 576 阅读 · 0 评论 -
hdu3646 Fate Stay Night(dp,读题障碍)
题目大意: 剑客VS狂战士。剑客的招数是依次召唤 N只火鸟攻击(为啥不叫召唤师),火鸟体力不一定相同。而狂战士有 K条命,火鸟一滴血换狂战士一滴血,直到一方体力为0。狂战士体力为0并且还有剩余生命则涅槃重生。火鸟刚招出来是YoungBrid,若杀死过狂战士,则变成OldBrid。剑客可以使用 M次咒语,每次可以使当前火鸟的体力*2。(要求最优状态,则肯定是在刚放出火鸟时施放咒语) 攻击规则:转载 2015-11-01 19:15:08 · 767 阅读 · 0 评论 -
【codechef】s=abs(这部分数-剩下的数),求所有选取方式的s之和
https://www.codechef.com/KOL15MOS/problems/KOL1502 印度的区域赛,很遗憾赛后不能提交了。。。 原本一直找不到正确的AC打开方式,实在也算道脑洞题吧。下午课上突然想到如何解题了,这种灵光一现的时刻多一点该有多好。。。 一组数据,从中选取一部分数,s=max(这部分数-剩下的数,剩下的数-这部分数),即abs(这部分数-剩下的数)。求所有选取方式的原创 2015-12-28 20:00:20 · 804 阅读 · 0 评论 -
【编程之美挑战赛】回文字符序列(区间dp)
给定字符串,求它的回文子序列个数。回文子序列反转字符顺序后仍然与原序列相同。例如字符串aba中,回文子序列为"a", "a", "aa", "b", "aba",共5个。内容相同位置不同的子序列算不同的子序列。 输入 第一行一个整数T,表示数据组数。之后是T组数据,每组数据为一行字符串。 输出 对于每组数据输出一行,格式为"Case #X: Y",X代表数据编号(从1开始)原创 2015-04-18 15:38:22 · 513 阅读 · 0 评论 -
zoj3738 Buy the Pets(人、猫、狗 DP)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5120 dp[i][j]表示取到第i个人第j种状态时的方案数。不过……为什么只能取 #include using namespace std; bool x[45][45]; long long dp[2][1<<21]; int n,m,p,q; int main(原创 2015-09-07 00:05:07 · 722 阅读 · 0 评论 -
zoj 3331 Process the Tasks(双塔DP)
There are two machines A and B. There are n tasks, namely task 1, task 2, ..., task n. You must assign each task to one machine to process it. There are some facts you must know and comply with: Yo原创 2015-04-16 15:40:38 · 810 阅读 · 0 评论 -
CF611D 【分割字符串使得形成的数字数组呈递增状态】的方法数
这题比较巧妙的是运用最长公共前缀长度简化问题以及运用sum数组缩减复杂度。注意要求分割后所有数字不得出现前导零。 没用sum数组的超时代码: #include #define ll long long #define mod 1000000007 using namespace std; int lcp[5001][5001]; ll dp[5001][5001]; int main(原创 2016-02-12 22:38:59 · 776 阅读 · 0 评论 -
CF543C 让所有的串成为独特的串的最小代价(状压dp,贪心)
题意(转):给定n个长度为m的字符串。为了让每个字符串变为独特的(该字符串的某一个位置存在一个字符ch,其他串的这个位置都不存在这个字符ch),你可以改变某些字符串的某些字符。现在告诉你改变每个字符的代价,求让所有的串成为独特的串的最小代价。 两个转移(对某行某列的字母): 1、直接修改本行的字母 2、把所有在该列拥有该字母的行都修改成别的字母。只需修改x-1个,留下权值最大原创 2016-02-16 22:51:56 · 775 阅读 · 0 评论 -
CF629C 在s两端在加两个串p和q 使得总长度为n,并且最后的s'符合规范的方法
给你一个长度为m的只含()的括号串s, 要求在s两端在加两个串p和q, 使得总长度为n,并且最后的s'(即p+s+q)是符合规范的。求添加p、q的方法数 可以在现有思路上+点击打开链接这题二维代码的理解。 还有一种做法:点击打开链接原创 2016-02-23 22:37:52 · 1539 阅读 · 0 评论 -
CF544C&51nod1086【限定个数的完全背包】
题意非常地晦涩难懂。 有n个程序员总共必须要码m行代码,其中每个程序员平均每行会出现的bug有x[i]个,问在总bug不超过b个的情况下有多少种方案(不是按每行是谁码的来区分,是按最终每个人码了多少行来区分)? dp(i,j,k):前i个程序员写了j行产生k个BUG的方案数。i省略。 #include #define ll long long //#define mod 100000000原创 2016-02-18 15:49:01 · 642 阅读 · 0 评论 -
hznu1858 至少选k个点框起来的最小正方形的边长
这题很容易想到二分+离散化+枚举。然而我没有想出来的点有如下: 1.枚举的到底是什么(如果说是把某个点作为正方形左上顶点枚举,肯定不对,然后就没想法了)。但是我想到了必定会有两个顶点在两条相交的边上。于是把所有点的横坐标放在集合{x},把所有点的纵坐标放在集合{y},于是最后就是枚举{x}*{y}种可能(★) 2.由于数据有1500,所以在每个二分的枚举里面不能直接的算出区域里个数(会超时),原创 2016-03-09 22:02:35 · 1095 阅读 · 2 评论 -
ZOJ 3929 Deque and Balls
放在这里为了警醒我以后不要出现太多低级bug。。。 #include #define ll long long #define mod 1000000007 using namespace std; ll power[100005]; ll r[100005]; ll dp[100005]; int main(){ power[0]=1; for(int i=1;i<=100000;++i)原创 2016-04-10 21:01:08 · 921 阅读 · 0 评论 -
hdu4466 将长度为n线段瓜分成若干个相似三角形,有多少种分法(划分dp)
三角形顺序不同视为不同方案。 题解:http://www.cnblogs.com/jianglangcaijin/p/3465526.html #include #define ll long long #define mod 1000000007 #define maxn 5000000 using namespace std; int dp[maxn+5]; int power[原创 2016-04-18 00:50:02 · 955 阅读 · 0 评论 -
hznu 1524 排队买票(dp)【类卡特兰构造】
有M个小孩到公园玩,门票是1元。其中N个小孩带的钱为1元,K个小孩带的钱为2元。售票员没有零钱,问这些小孩共有多少种排队方法,使得售票员总能找得开零钱。注意:两个拿一元零钱的小孩,他们的位置互换,也算是一种新的排法。(M<=10)输入输入一行,M,N,K(其中M=N+K,M<=10)。输出输出一行,总的排队方案。样例输入4 2 2样例输出8http://hsacm.cn/JudgeOn...原创 2015-05-03 20:07:32 · 2937 阅读 · 1 评论 -
CF176B 求经过K步使a串变成b串的方法
http://codeforces.com/problemset/problem/176/B 这题比赛的时候角度完全想错了。。。当时我的想法是转化成:“n+p*len=m个(1到len-1)的数相加"的方法数,p是圈数,复杂度10^8。 真的想不到这个dp方法。搬运其他大佬的解法: 1.首先原串(即以0号字母开头的)个数为1,其他种类串为0。 2.第一次变化之后,原串个数即原创 2017-03-08 19:53:31 · 823 阅读 · 0 评论 -
编程之美初赛第二场 扑克牌(四维dp,难)
一副不含王的扑克牌由52张牌组成,由红桃、黑桃、梅花、方块4组牌组成,每组13张不同的面值。现在给定52张牌中的若干张,请计算将它们排成一列,相邻的牌面值不同的方案数。 牌的表示方法为XY,其中X为面值,为2、3、4、5、6、7、8、9、T、J、Q、K、A中的一个。Y为花色,为S、H、D、C中的一个。如2S、2H、TD等。 输入 第一行为一个整数T,为数据组数。 之后每组数据占一行。这原创 2015-05-01 10:45:04 · 1147 阅读 · 0 评论 -
POJ-1243 One Person (经典级dp)猜数字
In the game show "The Price is Right", a number of players (typically 4) compete to get on stage by guessing the price of an item. The winner is the person whose guess is the closest one not exceeding转载 2015-04-06 23:13:26 · 954 阅读 · 0 评论 -
Poj 2096 Collecting Bugs(概率(期望)+dp)
/** dp求期望的题。 题意:一个软件有s个子系统,会产生n种bug。 某人一天发现一个bug,这个bug属于某种bug,发生在某个子系统中。 求找到所有的n种bug,且每个子系统都找到bug,这样所要的天数的期望。 需要注意的是:bug的数量是无穷大的,所以发现一个bug,出现在某个子系统的概率是1/s, 属于某种类型的概率是1/n。转载 2015-04-05 14:28:34 · 502 阅读 · 0 评论 -
POJ2411: Mondriaan's Dream(1*2铺地砖,DP)
Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of h原创 2015-04-11 18:41:07 · 1183 阅读 · 0 评论 -
【codechef】Yet Another Problem On Strings (找最优解)
You are given a string X consisting of lowercase alphabets. You are required to generate the largest stringY from X by following the given instructions below: frequency(Y[i]) in X >= frequency(Y[j]原创 2015-04-14 11:00:05 · 649 阅读 · 0 评论 -
zoj 2852 Deck of Cards扑克牌(三维dp)
21-point is a small game played with cards. Its aim is to accumulate the points on the cards so as to get 21 points. This game also appears on some cell phones. To simplify the problem, let's have原创 2015-04-19 21:27:22 · 839 阅读 · 0 评论 -
hznu 1652 能量项链(dp,难)
在Mars星球上,每个Mars人都随身佩带着一串能量项链。在项链上有 N颗能量珠。能量珠是一颗有头标记与尾标记的珠子,这些标记对应着某个正整数。并且,对于相邻的两颗珠子,前一颗珠子的尾标记一定等于后一颗珠子的头标 记。因为只有这样,通过吸盘(吸盘是Mars人吸收能量的一种器官)的作用,这两颗珠子才能聚合成一颗珠子,同时释放出可以被吸盘吸收的能量。如果前一颗 能量珠的头标记为m,尾标记为r,后一颗能原创 2015-04-16 22:46:04 · 533 阅读 · 0 评论 -
zoj 3329 One Person Game(概率(期望)+dp)经典
There is a very simple and interesting one-person game. You have 3 dice, namely Die1, Die2 and Die3. Die1 has K1 faces.Die2 has K2 faces. Die3 has K3 faces. All the dice are fair dice, so the probab原创 2015-04-05 14:05:02 · 599 阅读 · 0 评论 -
zoj3872 Beauty of Array(dp)
Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous原创 2015-04-29 10:29:20 · 608 阅读 · 0 评论 -
【codechef】Magical Transformation(dp,技巧题)
Irfan and his brother Yusuf were looking at photographs of their vacation to Hawaii. Irfan noticed something interesting. He noticed that if their aunt Mansi had a big beard and a moustache she would原创 2015-05-09 15:19:06 · 536 阅读 · 0 评论 -
ZOJ 3725 Painting Storages(很好的dp题)
There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to paint all storages with two colors: red and blue. Each storage will be painted with exactly one color.原创 2015-05-09 11:06:25 · 526 阅读 · 0 评论 -
hdu 4734 F(x)(数位dp,记忆化深搜,灵活题)
For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight as F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1. Now you are given two numbers A and B, please calculate ho原创 2015-05-09 21:49:41 · 602 阅读 · 0 评论 -
zoj 2949 Coins of Luck 抛硬币(概率(期望)+dp)
Luck is the key to life. When I have to decide something, I will make my decision by flipping a coin. And then, I have two things to do. First, I have the decision made. Second, I go to the nearest ch原创 2015-04-09 18:55:34 · 689 阅读 · 0 评论 -
【codechef】Steady tables(dp)
Input: 3 1 1 2 2 2 3 Output: 2 25 273 Explanation Test case 1 : There are only 2 such grids possible 0 and 1. http://www.codechef.com/JUNE15/problems/STDYTAB 这题没考虑到DP是我的错。。一直以为是推规律。。原创 2015-06-16 23:07:38 · 498 阅读 · 0 评论 -
【codechef】Strategy for the World Cup(组合打表)
Input: 6 10 2 9 6 2 9 6 1 9 4 1 9 5 1 9 10 3 9 Output: 2 4 1 1 0 12 http://www.codechef.com/COOK55/problems/WORLDCUP 组合和0-l的组合累加都要先打好表,不然会超时。 #include using namespace std; #define M 1000000007原创 2015-05-19 19:23:02 · 421 阅读 · 0 评论 -
【codechef】Kisses(dp,技巧题)
Mohit and his girlfriend are playing a game named 'Ascending sort'. The norms of the game are as follows : Initialy N integers are taken randomly and are kept on the table. The one who makes these原创 2015-04-19 18:54:05 · 670 阅读 · 0 评论 -
hdu 5234 Happy birthday(格子图上的01背包)
今天是Gorwin的生日。所以她的妈妈要实现她的一个愿望。Gorwin说她想吃很多蛋糕。所以他妈妈带她来到了蛋糕园。 这个园子被分成了n*m个方格子。在每一个格子里面,有一个蛋糕。第i行,第j列的格子中有一个重量为wij千克的蛋糕,Gorwin从左上角(1,1)的格子开始走,走到右下角(n,m)的格子。在每一步中,Gorwin可以向右或者向下走,即是:Gorwin站在(i,j)的时候,她可以走向原创 2015-06-09 21:55:15 · 538 阅读 · 0 评论
分享