HDU 4111 Alice and Bob 【DP解决博弈】
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4111题目大意:详见http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1719解题思路:开始的时候一直在推规律。但是很苦x,比赛到最后都没推出来。看了解题报告的状态转移方程才ac了此题。 最终的石子都会化成一堆。但是如果合并的话将奇偶性改变了一下,相当于缓了一步。由于一堆石子只有一个很特殊。因此状态转移方程将他分开考虑。dp[i][j]:表示i个1堆石子 ,将非一石子合并后的总数。dp[i][j]=
阅读全文
posted @
2013-04-03 20:17
crying_Dream
阅读(393)
推荐(0)
POJ 1170 Shoping Offers(IOI 95)
摘要:/*@@2013-02-0623:07*/题目大意:题目给出商品数量不超过5,用5元组表示商品i的购买数量。优惠政策也不超过99因此用f[a1][a2][a3][a4][a5]表示第i种商品买ai的数量的最小费用用s[i][j]表示第i种政策j件物品的购买数量,s[i][0]表示政策i的优惠价格重新处理商品的编号为输入的顺序。用map<int,int>实现状态转移方程:f[a1][a2][a3][a4][a5]=min{f[a1-s[i][1]][a2-s[i][2]][a3-s[i][3]][a4-s[i][4]][a5-s[i][5]]+s[i][0]};代码如下:View C
阅读全文
posted @
2013-03-02 09:53
crying_Dream
阅读(260)
推荐(0)
POJ 1322 Chocolate
摘要:http://poj.org/problem?id=1322题目大意:c种颜色的巧克力,拿出n块,桌子上有m块的概率是多少。如果桌子上出现相同颜色的巧克力那么将2块都吃掉分析:1》台上的巧克力数和当前拿出的巧克力的颜色有关系,设dp[i][j]表示拿出第i块的时候台上有j块巧克力的概率。巧克力i的颜色有两种情况:与桌上的巧克力颜色相同或者是与桌上的巧克力颜色不同状态转移方程为:dp[i][j]=dp[i-1][j-1]*p1+dp[i-1][j+2]*p2;p1=(c-j+1)/c,p2=(j+1)/c;2》状态i仅和i-1有关,可以进行空间上的优化,用滚动数组实现3》当拿出2*n+1奇数次巧
阅读全文
posted @
2013-03-02 09:51
crying_Dream
阅读(210)
推荐(0)
POJ 1189 钉子和小球
摘要:http://poj.org/problem?id=1189设经过位置(i,j)的小球个数为P(i,j),那么落入格子m的小球个数为p(n+1,m),那么概率就是p(n+1,m)/2^n。假设位置(i,j)有铁钉,那么各有p(i,j)/2个小球落入位置(i+1,j)和位置(i+1,j+1);否则球全部落入(i+2,j+1)的位置。代码如下:View Code /*POJ 1189钉子和球*/ #include<stdio.h>#include<string.h>#include<iostream>using namespace std;long long p
阅读全文
posted @
2013-03-02 09:49
crying_Dream
阅读(243)
推荐(0)
POJ 1179 Polygon
摘要:http://poj.org/problem?id=11791》给出的样例,取得的最优值为去掉2边后结果为:4*2*5-7=33。2》对于加法两个最优的相加肯定是最优的,但是对于乘法:求最大值:正数X正数两个都是最大的结果最大正数X负数正数最小,负数最大结果最大负数X负数两个都是最小值结果最大求最小值:正数X正数两个都是最小值结果最小正数X负数正数最大,负数最小结果最小负数X负数两个都最大结果最小要保存子问题的最大值和最小值,还具有点最优子结构,可以用动态规划求解。fmin(i,L)表示以i为首,顺时针长度为L的链的计算结果最小值。fmax(i,L)表示以i为首,顺时针长度为L的链的计算结果最
阅读全文
posted @
2013-03-02 09:45
crying_Dream
阅读(382)
推荐(0)
POJ 1338 Ugly Numbers
摘要:http://poj.org/problem?id=1338b最小的丑数是1,以后的丑数为在以前的基础上进行*2,*3,*5....那么设第i个丑数为F[i]=min{F[n2]*2,F[n3]*3,F[n5]*5},其中n2,n3,n5....表示进行衍生丑数的下标。暴力的打出1500个丑数要很久很久....才出来结果....代码如下:View Code /* POJ 1338丑数*/#include<stdio.h>#include<iostream>using namespace std;long long f[1505];long long minx(long
阅读全文
posted @
2013-03-02 09:41
crying_Dream
阅读(174)
推荐(0)
POJ 1191 棋盘分割【区间类DP】
摘要:http://poj.org/problem?id=11911>根据公式化简:其中后者是一个已知数。求均方差的最小值就是求出个个棋盘内各数值的平方和最小值。2>棋盘分割分四种情况:竖切(左不动),竖切(右不动),横切(上不动),横切(下不动);3>状态转移方程:f(i,x1,y1,x2,y2)表示以(x1,y1),(x2,y2)为四边形对角线的棋盘切割成i块的各块值总平方的最小值;D(x1,y1,x2,y2)表示棋盘的总分_____________|f(i-1,x1,a+1,x2,y2)+D(x1,y1,x2,a)[横切(上不动)]|f(i-1,x1,y1,x2,a)+D(x
阅读全文
posted @
2013-03-02 09:40
crying_Dream
阅读(213)
推荐(0)
POJ 1692 Crossed Matchings【DP】
摘要:DescriptionThere are two rows of positive integer numbers. We can draw one line segment between any two equal numbers, with values r, if one of them is located in the first row and the other one is located in the second row. We call this line segment an r-matching segment. The following figure shows
阅读全文
posted @
2012-10-11 20:40
crying_Dream
阅读(217)
推荐(0)
HRBUST 1541 集合划分【01背包】
摘要:Description对于从1到N (1 <= N <= 39) 的连续整数集合,能划分成两个子集合,且保证每个集合的数字和是相等的。举个例子,如果N=3,对于{1,2,3}能划分成两个子集合,每个子集合的所有数字和是相等的:{3} 和 {1,2}这是唯一一种分法(交换集合位置被认为是同一种划分方案,因此不会增加划分方案总数) 如果N=7,有四种方法能划分集合{1,2,3,4,5,6,7},每一种分法的子集合各数字和是相等的:{1,6,7} 和 {2,3,4,5} {注 1+6+7=2+3+4+5}{2,5,7} 和 {1,3,4,6}{3,4,7} 和 {1,2,5,6}{1,2
阅读全文
posted @
2012-09-14 10:35
crying_Dream
阅读(230)
推荐(0)
POJ 3124 The Bookcase【dp]
摘要:DescriptionNo wonder the old bookcase caved under the massive piles of books Tom had stackedon it. He had better build a new one, this time large enough to hold all of his books. Tomfinds it practical to have the books close at hand when he works at his desk. Therefore, he is imagining a compact sol
阅读全文
posted @
2012-09-14 09:50
crying_Dream
阅读(415)
推荐(0)
HRBUST 1473 教主的遗产【状态压缩】
摘要:Description恭送教主!教主在2012年7月19日上午10:48,坐上前往北京的火车,从此开始了高富帅的生活。在教主的的大学四年ACM生涯中,他用事实告诉我们,要想在比赛拿奖,除了平时的刻苦努力外,很大一部分还要依赖比赛时是做题策略,简单来讲就是做题顺序,唯有想把能过的都过掉,然后再过难题,这样才能在比赛中拿奖。我们将用这个做题顺序量化表示,即AC系数,AC系数越大,拿奖可能性就越大。在比赛中会给出n个题,不同做题顺序会有不同的AC系数,假如A先做,B后做的话,B对A的AC系数为4, 反过来 B先做,A后做的话,A对B的AC系数为5,说明先做B后做A将得到更高的AC系数。设Sij表示第
阅读全文
posted @
2012-09-07 09:16
crying_Dream
阅读(209)
推荐(0)
ZOJ 3471 Most Powerful 【状态压缩】
摘要:Recently, researchers on Mars have discovered N powerful atoms. All of them are different. These atoms have some properties. When two of these atoms collide, one of them disappears and a lot of power is produced. Researchers know the way every two atoms perform when collided and the power every two
阅读全文
posted @
2012-09-06 21:19
crying_Dream
阅读(210)
推荐(0)
POJ 3254 Corn Fields【状态压缩】
摘要:DescriptionFarmer John has purchased a lush new rectangular pasture composed ofMbyN(1 ≤M≤ 12; 1 ≤N≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can't be planted. Canny FJ knows that the cows dislike
阅读全文
posted @
2012-09-06 00:36
crying_Dream
阅读(606)
推荐(0)
HDU 1069 Monkey and Banana【DP】
摘要:Problem DescriptionA group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block on
阅读全文
posted @
2012-07-31 18:56
crying_Dream
阅读(184)
推荐(0)
HDU 1024 Max Sum Plus Plus【DP+优化时间复杂度】
摘要:Problem DescriptionNow I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.Given a consecutive number sequence S1, S2, S3, S4 ... Sx, ... Sn (1 ≤ x ≤
阅读全文
posted @
2012-07-31 18:53
crying_Dream
阅读(232)
推荐(0)
HDU 1501 Zipper【DP】
摘要:Problem DescriptionGiven three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in its original order.For example, consider forming "tcraete" from &q
阅读全文
posted @
2012-07-31 18:51
crying_Dream
阅读(163)
推荐(0)
HDU 1078 FatMouse and Cheese【记忆化搜索】
摘要:Problem DescriptionFatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q < n. At each grid location Fatmouse has hid between 0 and 100 blocks of cheese in a hole. Now he'
阅读全文
posted @
2012-07-31 18:48
crying_Dream
阅读(196)
推荐(0)
POJ 2378 Tree Cutting【树形DP】
摘要:DescriptionAfter Farmer John realized that Bessie had installed a "tree-shaped" network among his N (1 <= N <= 10,000) barns at an incredible cost, he sued Bessie to mitigate his losses. Bessie, feeling vindictive, decided to sabotage Farmer John's network by cutting power to one
阅读全文
posted @
2012-07-31 18:44
crying_Dream
阅读(249)
推荐(0)
POJ 3107 Godfather 【树形DP】
摘要:DescriptionLast years Chicago was full of gangster fights and strange murders. The chief of the police got really tired of all these crimes, and decided to arrest the mafia leaders.Unfortunately, the structure of Chicago mafia is rather complicated. There are n persons known to be related to mafia.
阅读全文
posted @
2012-07-31 18:41
crying_Dream
阅读(402)
推荐(0)
POJ 1655 Balancing Act【树形DP】POJ 1655 Balancing Act Balancing Act POJ 1655
摘要:DescriptionConsider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any node from the tree yields a forest: a collection of one or more trees. Define the balance of a node to be the size of the largest tree in the forest T created by deleting that node from T. For example, co
阅读全文
posted @
2012-07-31 18:39
crying_Dream
阅读(169)
推荐(0)