摘要: http://poj.org/problem?id=3280 对字符串进行增删操作使其形成回文串,每次操作都有其对应的花费,求最小花费。 典型DP,dp[i][j]为使str[j, i]形成回文的最小花费。 若str[j]==str[i],则dp[i][j]由dp[i-1][j+1]而来。 若str[j]!=str[i],则dp[i][j]=min(dp[i-1][j]+v[data[i]], dp[i][j+1]+v[data[j]]) ;v[data[j]]为增减字符j所花费最小值,因为增加一个字符和减少一个字符起到的效果是相同的,所以预处理出数组v即可。 练习赛时就是没想到预处理这一.. 阅读全文
posted @ 2012-04-14 21:45 追逐. 阅读(203) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1252 先计算6种钱币相加的情况,有f[j] = min(f[j], f[j-data[i]]+1) ; 然后计算找零的情况,有f[j] = min(f[j], f[j+data[i]]+1) ; 计算的上限要比100大,因为有找零的情况,但是要大多少不太好确定。code:#include<cstdio>#include<cstring>#include<algorithm>usingnamespacestd;constintMax=2500;//..intdata[6],f[Max];intmain() 阅读全文
posted @ 2012-04-14 08:37 追逐. 阅读(227) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3600 枚举subimage第一行在image中的位置,然后在image中选取c列,若这c列中有r行和subimage相同,那么即为有解。code:#include<cstdio>#include<cstring>#include<iostream>usingnamespacestd;intvis[21];charsmap[21][21],imap[21][21];intr,c,R,C,flag;intcheck(intcr){//判断imap中是否有r行与smap相同inti,j,count=0,x=0 阅读全文
posted @ 2012-04-14 08:30 追逐. 阅读(355) 评论(0) 推荐(1) 编辑