poj 3280 区间dp
来源:互联网 发布:java定义日期变量 编辑:程序博客网 时间:2024/05/29 08:32
题意是给你一个串 让你增加字母和去掉字母把它变为回文串 增加或删除室友花费的 问最小花费;
可以看出增加和删除性质是一样的 所有去其中较小的 dp【i】【j】 表示i到j的最小花费 如果str【i】==str【j】 则dp【i】【j】=dp【i+1】【j-1】否则
dp[i][j]=min(dp[i+1][j]+cost[str[i]-'a'],dp[i][j-1]+cost[str[j]-'a']); 直接暴力就行了
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define INF 0x3f3f3f3f
int min(int a,int b)
{
return a<b?a:b;
}
int dp[2010][2010];
int main()
{
char str[2010];
char p[2];
int cost[30];
int i,j,n,len;
while(~scanf("%d%d",&n,&len))
{
scanf("%s",str);
memset(cost,0,sizeof(cost));
for(i=1;i<=n;i++)
{
int a,b;
scanf("%s%d%d",p,&a,&b);
cost[p[0]-'a']=min(a,b);
}
memset(dp,0,sizeof(dp));
for(i=len-1;i>=0;i--)
{
for(j=i+1;j<len;j++)
{
dp[i][j]=min(dp[i+1][j]+cost[str[i]-'a'],dp[i][j-1]+cost[str[j]-'a']);
if(str[i]==str[j]) dp[i][j]=min(dp[i][j],dp[i+1][j-1]);
}
}
printf("%d\n",dp[0][len-1]);
}
return 0;
}
- POJ 3280 区间DP
- poj 3280 区间dp
- poj 3280 区间dp
- POJ 3280 (区间DP)
- POJ 3280 区间dp
- poj 3280 区间dp
- POJ 3280-区间DP
- POJ 3280 简单区间 DP
- POJ 3280(区间dp)
- poj 3280(简单区间dp)
- poj 3280 区间dp水题
- poj 3280 Cheapest Palindrome(区间DP)
- POJ 3280 Cheapest Palindrome (区间dp)
- poj 3280 Cheapest Palindrome (区间DP)
- poj 3280 Cheapest Palindrome (区间dp)
- poj 3280 Cheapest Palindrome(区间dp)
- Cheapest Palindrome (poj 3280 区间DP)
- [区间dp] poj 3280 Cheapest Palindrome
- hdu 2476 区间dp
- eclipse 导入框架app 报错
- AppDelegate单例模式、通过StoryBoardId加载ViewController Swift
- ubuntu12.04指令和基本问题
- PureMVC(AS3)剖析:实例
- poj 3280 区间dp
- 使用 Spring Boot 快速构建 Spring 框架应用
- 利用windows定时任务备份项目
- 对于Linux内核tty设备的一点理解
- C语言数组a[i]==i[a]
- 在eclipse中关联Hadoop源代码
- Web前端问题总结A
- 视频通话问题总结
- 编写自己的JDBC框架(九)