随笔分类 -  动态规划

Hotel
摘要:Problem DescriptionLast year summer Max straveled to California for his vacation. He had a great time there: took many photos, visited famous universities, enjoyed beatiful beaches and tasted various delicius foods. It is such a good trip that Max plans to travel there one more time this year. Max i 阅读全文

posted @ 2013-08-16 23:39 forevermemory 阅读(222) 评论(0) 推荐(0)

河床
摘要:Problem Description地理学家们经常要对一段河流进行测量分析。他们从上游开始向下游方向等距离地选择了n(int dp[30005][101];int a[30005];int main(){ int i,n,test,j,k,x,ma; scanf("%d",&test); while(test--) { scanf("%d%d",&n,&k); for(i=0;i=0&&xma) ma=dp[i][j]; } } printf("%d\n",ma); } retu... 阅读全文

posted @ 2013-08-07 11:05 forevermemory 阅读(217) 评论(0) 推荐(0)

病毒
摘要:Problem Description你有一个日志文件,里面记录着各种系统事件的详细信息。自然的,事件的时间戳按照严格递增顺序排列(不会有两个事件在完全相同的时刻发生)。遗憾的是,你的系统被病毒感染了,日志文件中混入了病毒生成的随机伪事件(但真实事件的相对顺序保持不变)。备份的日志文件也被感染了,但由于病毒采用的随机感染方法,主日志文件和备份日志文件在感染后可能会变得不一样。给出被感染的主日志和备份日志,求真实事件序列的最长可能长度。Input输入第一行为数据组数T (T#includeint main(){int a[1005],b[1005],la,lb,f[1005];int i,j,n 阅读全文

posted @ 2013-07-30 15:28 forevermemory 阅读(245) 评论(1) 推荐(0)

Starship Troopers
摘要:Problem DescriptionYou, the leader of Starship Troopers, are sent to destroy a base of the bugs. The base is built underground. It is actually a huge cavern, which consists of many rooms connected with tunnels. Each room is occupied by some bugs, and their brains hide in some of the rooms. Scientist 阅读全文

posted @ 2013-07-27 13:43 forevermemory 阅读(206) 评论(0) 推荐(0)

龟兔赛跑
摘要:Problem Description据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成了绝技,能够毫不休息得以恒定的速度(VR m/s)一直跑。兔子一直想找机会好好得教训一下乌龟,以雪前耻。 最近正值HDU举办50周年校庆,社会各大名流齐聚下沙,兔子也趁此机会向乌龟发起挑战。虽然乌龟深知获胜希望不大,不过迫于舆论压力,只能接受挑战。 比赛是设在一条笔直的道路上,长度为L米,规则很简单,谁先到达终点谁就算获胜。 无奈乌龟自从上次获胜以后,成了名龟,被一些八卦杂志称为“动物界的刘翔”,广告不断,手 阅读全文

posted @ 2013-07-26 22:19 forevermemory 阅读(306) 评论(0) 推荐(0)

Pascal's Travels
摘要:Problem DescriptionAn n x n game board is populated with integers, one nonnegative integer per square. The goal is to travel along any legitimate path from the upper left corner to the lower right corner of the board. The integer in any one square dictates how large a step away from that location mu 阅读全文

posted @ 2013-07-21 17:02 forevermemory 阅读(232) 评论(0) 推荐(0)

FatMouse's Speed
摘要:Problem DescriptionFatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.InputInput con 阅读全文

posted @ 2013-07-20 11:48 forevermemory 阅读(173) 评论(0) 推荐(0)

漫步校园
摘要:Problem DescriptionLL最近沉迷于AC不能自拔,每天寝室、机房两点一线。由于长时间坐在电脑边,缺乏运动。他决定充分利用每次从寝室到机房的时间,在校园里散散步。整个HDU校园呈方形布局,可划分为n*n个小方格,代表各个区域。例如LL居住的18号宿舍位于校园的西北角,即方格(1,1)代表的地方,而机房所在的第三实验楼处于东南端的(n,n)。因有多条路线可以选择,LL希望每次的散步路线都不一样。另外,他考虑从A区域到B区域仅当存在一条从B到机房的路线比任何一条从A到机房的路线更近(否则可能永远都到不了机房了…)。现在他想知道的是,所有满足要求的路线一共有多少条。你能告诉他吗?Inp 阅读全文

posted @ 2013-07-18 09:15 forevermemory 阅读(138) 评论(0) 推荐(0)

Function Run Fun
摘要:Problem DescriptionWe all love recursion! Don't we?Consider a three-parameter recursive function w(a, b, c):if a 20 or b > 20 or c > 20, then w(a, b, c) returns: w(20, 20, 20)if a using namespace std;int p[22][22][22];int fun(int a,int b,int c){if(a20||j>20||k>20) return p[20][20][20 阅读全文

posted @ 2013-07-17 11:15 forevermemory 阅读(255) 评论(0) 推荐(0)

Employment Planning
摘要:Problem DescriptionA project manager wants to determine the number of the workers needed in every month. He does know the minimal number of the workers needed in each month. When he hires or fires a worker, there will be some extra cost. Once a worker is hired, he will get the salary even if he is n 阅读全文

posted @ 2013-07-17 09:55 forevermemory 阅读(235) 评论(0) 推荐(0)

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 #includeint dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};int mm[105][105],a[105][105];int n,k;int dfs(int x,int y){ if(mm[x][y]>0) return 阅读全文

posted @ 2013-07-16 23:20 forevermemory 阅读(171) 评论(0) 推荐(0)

Monkey and Banana
摘要: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 @ 2013-06-28 13:46 forevermemory 阅读(223) 评论(0) 推荐(0)

How to Type
摘要:Problem DescriptionPirates have finished developing the typing software. He called Cathy to test his typing software. She is good at thinking. After testing for several days, she finds that if she types a string by some ways, she will type the key at least. But she has a bad habit that if the caps l 阅读全文

posted @ 2013-05-28 17:56 forevermemory 阅读(360) 评论(0) 推荐(0)

humble numbers
摘要:Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers. Write a program to find and print the nth element in this sequence Input The inp. 阅读全文

posted @ 2013-05-28 11:18 forevermemory 阅读(145) 评论(0) 推荐(0)

jump(最大递增子序列和)
摘要:Problem DescriptionNowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some 阅读全文

posted @ 2013-05-27 20:40 forevermemory 阅读(188) 评论(0) 推荐(0)

搬寝室
摘要:Problem Description搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆,因为n是一个小于2000的整数,实在是太多了,于是xhd决定随便搬2*k件过去就行了.但还是会很累,因为2*k也不小是一个不大于n的整数.幸运的是xhd根据多年的搬东西的经验发现每搬一次的疲劳度是和左右手的物品的重量差的平方成正比(这里补充一句,xhd每次搬两件东西,左手一件右手一件).例如xhd左手拿重量为3的物品,右手拿重量为6的物品,则他搬完这次的疲劳度为(6-3)^2 = 9.现在可怜的xh 阅读全文

posted @ 2013-05-27 17:37 forevermemory 阅读(170) 评论(0) 推荐(0)

Missile
摘要:Problem DescriptionLong, long ago, country A invented a missile system to destroy the missiles from their enemy. That system can launch only one missile to destroy multiple missiles if the heights of all the missiles form a non-decrease sequence. But recently, the scientists found that the system is 阅读全文

posted @ 2013-04-21 23:30 forevermemory 阅读(387) 评论(0) 推荐(0)

最大连续子序列
摘要:Problem Description给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j <= K。最大连续子序列是所有连续子序列中元素和最大的一个, 例如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为{ 11, -4, 13 },最大和 为20。 在今年的数据结构考卷中,要求编写程序得到最大和,现在增加一个要求,即还需要输出该 子序列的第一个和最后一个元素。Input测试输入包含若干测试用例,每个测试用例占2行,第1行给出正整数K( &l 阅读全文

posted @ 2013-04-19 22:17 forevermemory 阅读(459) 评论(0) 推荐(0)

WXYZ与绿豆饼
摘要:Problem DescriptionWXYZ很喜欢吃绿豆饼,而且每次都能吃很多。但是担心WXYZ长的太胖,妈妈把买回来的一卷卷的绿豆饼排成一列(每卷绿豆饼的高度可能是不一样的),规定WXYZ只能取其中一段连续的并且高度严格上升的绿豆饼来吃。 可怜的WXYZ发现,根据这个规则,每次他只能拿到很少的绿豆饼,于是他想到了一个办法:趁妈妈不注意的时候改变某一卷绿豆饼的高度(压扁或拉长它)。WXYZ知道,这样就可以拿到一段长得多的连续的而且高度严格上升的绿豆饼了。 真是太聪明了!不过应该改变哪一卷绿豆饼的高度才能使得可以拿走的连续的一段高度严格上升的绿豆饼最多呢?嗯,这个问题就交给你了,如果你能成功解 阅读全文

posted @ 2013-04-18 22:58 forevermemory 阅读(388) 评论(0) 推荐(0)

City Road
摘要:Problem DescriptionLong long ago, city Old was all around the water and was divided into M*N small square houses. The city Old had only two bridges, in the southwest corner and northeast corner. It’s obvious that the citizens can have C(m+n, n) different ways with shortest length, to go from one bri 阅读全文

posted @ 2013-04-15 22:41 forevermemory 阅读(286) 评论(0) 推荐(0)