1710: [Usaco2007 Open]Cheappal 廉价回文
2017-09-14 08:44
399 查看
题目链接
题目大意:给出删掉和添加每种字符的花费,求把字符串变成回文串的最小花费
题解:加入一个字母等价于在对称位置删除一个字母,所以费用取较小的就可以
然后根据知识知道回文串一般在串两边进行操作,据此大力转移
我的收获:……
题目大意:给出删掉和添加每种字符的花费,求把字符串变成回文串的最小花费
题解:加入一个字母等价于在对称位置删除一个字母,所以费用取较小的就可以
然后根据知识知道回文串一般在串两边进行操作,据此大力转移
我的收获:……
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int M=2005; int n,m,f[M][M],cost[255]; char str[M]; int dfs(int l,int r) { if(r<1||l>m) return 0; if(l==r) return 0; if(f[l][r]!=-1) return f[l][r]; int res=1000000; res=min(dfs(l+1,r)+cost[str[l]],dfs(l,r-1)+cost[str[r]]); if(str[l]==str[r]) res=min(res,dfs(l+1,r-1)); return f[l][r]=res; } void work() { memset(f,-1,sizeof(f)); printf("%d\n",dfs(1,m)); } void init() { char tmp[50];int w1,w2; scanf("%d%d%s",&n,&m,str+1); for(int i=1;i<=n;i++) { scanf("%s%d%d",tmp,&w1,&w2); cost[tmp[0]]=min(w1,w2); } } int main() { init(); work(); return 0; }
相关文章推荐
- bzoj1710【Usaco2007 Open】Cheappal 廉价回文
- BZOJ 1710: [Usaco2007 Open]Cheappal 廉价回文
- bzoj 1710: [Usaco2007 Open]Cheappal 廉价回文【区间dp】
- BZOJ 1710: [Usaco2007 Open]Cheappal 廉价回文 区间dp
- 【BZOJ1710】[Usaco2007 Open]Cheappal 廉价回文【区间DP】
- 动态规划 BZOJ1710 [Usaco2007 Open]Cheappal 廉价回文
- bzoj1710[Usaco2007 Open]Cheappal 廉价回文 dp
- bzoj 1710: [Usaco2007 Open]Cheappal 廉价回文 动态规划
- BZOJ1710: [Usaco2007 Open]Cheappal 廉价回文
- 1710: [Usaco2007 Open]Cheappal 廉价回文 (区间DP)
- bzoj1710【Usaco2007 Open】Cheappal 便宜回文
- 【bzoj1710/Usaco2007 Open】Cheappal 廉价回文——区间dp
- 1710: [Usaco2007 Open]Cheappal 廉价回文
- 【BZOJ】1710: [Usaco2007 Open]Cheappal 廉价回文
- BZOJ1645 [Usaco2007 Open]City Horizon 城市地平线
- [bzoj1647][Usaco2007 Open]Fliptile 翻格子游戏
- bzoj 1711: [Usaco2007 Open]Dining吃饭 网络流
- BZOJ1646: [Usaco2007 Open]Catch That Cow 抓住那只牛
- 【BZOJ】1646: [Usaco2007 Open]Catch That Cow 抓住那只牛(bfs)
- 2014.6.14模拟赛【bzoj1646】[Usaco2007 Open]Catch That Cow 抓住那只牛