欢迎访问我的个人网站==》 jiashubing.cn
摘要: String to Palindrome题目大意:给出一个字符串s,现在可以进行3种操作(添加字母,删除字母,替换字母),将其变成回文串,求出最少的操作次数。比如abccda,可以用删除操作,删除b,d两步可变成回文;但如果用替换操作,把b换成d则只需要1步。分析:刚开始我一直考虑它是否具有最优子结构性质,直到现在,还是不明白为什么可以用动态规划来做,大神若是看见,还望指教。 由于添加字母和删除字母的效果是一样的,因此我们这里就只进行删除和替换操作。令dp[i][j]表示从第 i 到第 j 个字母变成回文所需要最少的操作数。 转移方程为:当是s[i]==s[j]时,dp[i][j] = d.. 阅读全文
posted @ 2013-07-26 18:22 贾树丙 阅读(758) 评论(0) 推荐(0) 编辑
摘要: 题目大意:输入一个由小写字母组成的字符串,你的任务是把它划分成尽量少的回文串。比如racecar本身就是回文串;fastcar只能分成7个单字母的回文串;aaadbccb最少可分成3个回文串:aaa、d、bccb。字符串的长度不超过1000。分析:令dp[i]表示从第1个到第 i 个字符所组成的最少回文串数。 我们考虑如果前k个字符构成了1个回文,那么前k+1个字符最多构成2个回文,如果这些字符都相同,那么也只是1个回文串。所以如果第 j 个字母到第 i 个字母能构成回文,那么dp[i] = min(dp[i],dp[j-1]+1);初始条件是:dp[i]=i;代码如下: 1 # inclu. 阅读全文
posted @ 2013-07-26 16:38 贾树丙 阅读(343) 评论(0) 推荐(0) 编辑
摘要: 连连看Time Limit: 20000/10000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13730Accepted Submission(s): 3579Problem Description“连连看”相信很多人都玩过。没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子。如果某两个相同的棋子,可以通过一条线连起来(这条线不能经过其它棋子),而且线的转折次数不超过两次,那么这两个棋子就可以在棋盘上消去。不好意思,由于我以前没有玩过连连看,咨询了同学的意 阅读全文
posted @ 2013-07-26 15:06 贾树丙 阅读(371) 评论(1) 推荐(0) 编辑
摘要: Knight MovesTime Limit:2 Seconds Memory Limit:65536 KBA friend of you is doing research on theTraveling Knight Problem (TKP)where you are to find the shortest closed tour of knight moves that visits each square of a given set ofnsquares on a chessboard exactly once. He thinks that the most difficult 阅读全文
posted @ 2013-07-25 01:15 贾树丙 阅读(727) 评论(0) 推荐(0) 编辑
摘要: 又是类似骑士拯救公主,不过这个是朋友拯救天使的故事。。。不同的是,天使有多个朋友,而骑士一般单枪匹马比较帅~求到达天使的最短时间,杀死一个护卫1 units time , 走一个格子 1 unit time 。SO,杀死一个护卫到达那个格子 2units time。第一反应是广搜,就搜咧 = =。。WA了,交hdu上 AC了,hdu数据真弱啊。。。想了想,想通了,因为一般广搜的话必须都是1个时间才能搜,才能保证这个BFS树是等距离向外伸展的,而这个不是等距离的,所以需要一些处理。1、我的方法是,找到天使后,把时间比下大小,最后输出最小的。需要优化,只这么做的话,会TLE的,如果走过一个格子,这 阅读全文
posted @ 2013-07-22 18:18 贾树丙 阅读(283) 评论(0) 推荐(0) 编辑
摘要: CALCULATOR CONUNDRUMAlice got a hold of an old calculator that can displayndigits. She was bored enough to come up with the following time waster.She enters a numberkthen repeatedly squares it until the result overflows. When the result overflows, only thenmostsignificant digits are displayed on the 阅读全文
posted @ 2013-07-20 19:02 贾树丙 阅读(660) 评论(2) 推荐(1) 编辑
摘要: Open Credit SystemIn an open credit system, the students can choose any course they like, but there is a problem. Some of the students are more senior than other students. The professor of such a course has found quite a number of such students who came from senior classes (as if they came to attend 阅读全文
posted @ 2013-07-20 18:49 贾树丙 阅读(347) 评论(1) 推荐(1) 编辑
摘要: Age SortYou are given the ages (in years) of all people of a country with at least 1 year of age. You know that no individual in that country lives for 100 or more years. Now, you are given a very simple task of sorting all the ages in ascending order.InputThere are multiple test cases in the input 阅读全文
posted @ 2013-07-20 18:12 贾树丙 阅读(512) 评论(1) 推荐(0) 编辑
摘要: NetworkConsider a tree network withnnodes where the internal nodes correspond to servers and the terminal nodes correspond to clients. The nodes are numbered from 1 ton. Among the servers, there is an original serverSwhich provides VOD (Video On Demand) service. To ensure the quality of service for 阅读全文
posted @ 2013-07-20 18:05 贾树丙 阅读(536) 评论(1) 推荐(0) 编辑
摘要: Help is needed for DexterTime Limit: 3 SecondDexter is tired of Dee Dee. So he decided to keep Dee Dee busy in a game. The game he planned for her is quite easy to play but not easy to win at least not for Dee Dee. But Dexter does not have time to spend on this silly task, so he wants your help.Ther 阅读全文
posted @ 2013-07-20 15:25 贾树丙 阅读(422) 评论(1) 推荐(0) 编辑
摘要: Easy Problem from Rujia Liu?Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 2006, Beijing 2007 and Wuhan 2009, or UVa OJ contests like Rujia Liu's Presents 1 and 2), he occasionally sets easy problem (for example, 'the Coco-Cola Store&# 阅读全文
posted @ 2013-07-19 23:06 贾树丙 阅读(450) 评论(1) 推荐(0) 编辑
摘要: I Can Guess the Data Structure!There is a bag-like data structure, supporting two operations:1 xThrow an element x into the bag.2Take out an element from the bag.Given a sequence of operations with return values, you're going to guess the data structure. It is a stack (Last-In, First-Out), a que 阅读全文
posted @ 2013-07-19 22:44 贾树丙 阅读(452) 评论(1) 推荐(0) 编辑
摘要: strcmp() Anyone?strcmp() is a library function in C/C++ which compares two strings. It takes two strings as input parameter and decides which one is lexicographically larger or smaller: If the first string is greater then it returns a positive value, if the second string is greater it returns a nega 阅读全文
posted @ 2013-07-19 22:24 贾树丙 阅读(440) 评论(1) 推荐(0) 编辑
摘要: Remember the WordNeal is very curious about combinatorial problems, and now here comes a problem about words. Knowing that Ray has a photographic memory and this may not trouble him, Neal gives it to Jiejie.Since Jiejie can't remember numbers clearly, he just uses sticks to help himself. Allowin 阅读全文
posted @ 2013-07-19 21:50 贾树丙 阅读(683) 评论(1) 推荐(0) 编辑
摘要: Beijing GuardsBeijing was once surrounded by four rings of city walls: the Forbidden City Wall, the Imperial City Wall, the Inner City Wall, and finally the Outer City Wall. Most of these walls were demolished in the 50s and 60s to make way for roads. The walls were protected by guard towers, and th 阅读全文
posted @ 2013-07-19 01:48 贾树丙 阅读(515) 评论(0) 推荐(0) 编辑