随笔分类 -  UVA

摘要:最近觉得动态规划真的很练脑子,对建模以及思维方法有很大帮助,线段树被卡到有点起不来的感觉最近仔细思考了一下动态规划的思想,无非是由局部最优解得到全局最优解,由此类推,发现,像最短路和最小生成树其实都是动态规划的思想在里面。这题Chopstick,在建立状态 和 怎样递推 是两个难点。在建立状态方面,通过dp[i][j],n-i+1为可选的筷子数,j为已选筷子组数,所以最终要求的结果自然是 dp[1][k].递推方面,要注意两个细节,第一,每一组的那两根短筷子,必定是相邻的,可以反证法证明。第二,那根长筷子,如果采取逆推方式,就可以不用管了,因为逆推只要保证前面有长筷子即可。。。for(i=.. 阅读全文
posted @ 2013-09-09 11:37 KRisen 阅读(254) 评论(0) 推荐(0)
摘要:受教了,感谢玉斌大神的博客。这道题最难的地方就是操作2,将一个集合中的一个点单独移到另一个集合,因为并查集的性质,如果该点本身作为root节点的话,怎么保证其他点不受影响。玉斌大神的思路很厉害,受教受教,即,由于题目最终输出集合的元素个数与权值总和,故添加一个delete操作,将该点(设为P)所在集合的rank和sum值减小,将p的father引向一个从没定义过的点,(可以设置为(总数++)点),这样,虽然看似P还留在原集合,但仅仅作为一个空骨架,并不对集合的rank和sum产生影响。具体实现,需要借助一个辅助数组 id[], id[]初始和father[]相同,但一旦需要删除操作,即将id[ 阅读全文
posted @ 2013-08-10 15:33 KRisen 阅读(366) 评论(0) 推荐(0)
摘要:Where's Waldorf?Given a m by n grid of letters, ( ), and a list of words, find the location in the grid at which the word can be found. A word matches a straight, uninterrupted line of letters in the grid. A word can match the letters in the grid regardless of case (i.e. upper and lower case let 阅读全文
posted @ 2013-04-19 09:33 KRisen 阅读(175) 评论(0) 推荐(0)
摘要:One day, an ant called Alice came to an M*M chessboard. She wanted to go around all the grids. So she began to walk along the chessboard according to this way: (you can assume that her speed is one grid per second) At the first second, Alice was standing at (1,1). Firstly she went up for a grid, the 阅读全文
posted @ 2013-01-27 12:10 KRisen 阅读(221) 评论(0) 推荐(0)
摘要:ProductThe ProblemThe problem is to multiply two integers X, Y. (0<=X,Y<10250)The InputThe input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.The OutputFor each input pair of lines the output line should consist one integer the product.Sample Input12122222 阅读全文
posted @ 2013-01-20 18:12 KRisen 阅读(183) 评论(0) 推荐(0)
摘要:Integer InquiryOne of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and h... 阅读全文
posted @ 2013-01-18 16:09 KRisen 阅读(485) 评论(0) 推荐(0)
摘要:PalindromesA regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is read from right to left. A mirrored string is 阅读全文
posted @ 2013-01-17 16:24 KRisen 阅读(246) 评论(0) 推荐(0)