UVa 1625 Color Length
来源:互联网 发布:国家重点软件企业认定 编辑:程序博客网 时间:2024/05/01 04:19
题目和题解都在刘汝佳蓝皮书276页,讲的很详细,这里就不再废话了。
代码:
#include<cstdio>#include<iostream>#include<cstring>#define CLEAR(xxx) memset(xxx,0,sizeof(xxx))using namespace std;const int maxn=5000+5,inf=1e9;int n,m,f[maxn][maxn],fst[30][2],last[30][2];char s1[maxn],s2[maxn];int idx(char x){return x-'A';}void Init(){int i;//注意初值 CLEAR(last);for(i=0;i<26;i++) fst[i][0]=fst[i][1]=inf;scanf("%s%s",s1+1,s2+1);n=strlen(s1+1); m=strlen(s2+1);for(i=1;i<=n;i++){int id=idx(s1[i]);if(fst[id][0]==inf) fst[id][0]=i;last[id][0]=i;}for(i=1;i<=m;i++){int id=idx(s2[i]);if(fst[id][1]==inf)fst[id][1]=i;last[id][1]=i;} } int main(){int T,i,j,k;scanf("%d",&T);while(T--){Init();for(i=0;i<=n;i++)for(j=0;j<=m;j++){int cnt=0,_min=inf;for(k=0;k<26;k++) //统计在序列中而尚未结束的颜色个数 if((fst[k][0]<=i||fst[k][1]<=j)&&(last[k][0]>i||last[k][1]>j))cnt++;if(i>0)_min=min(_min,f[i-1][j]);if(j>0)_min=min(_min,f[i][j-1]); f[i][j]=cnt+ (_min==inf? 0:_min);}printf("%d\n",f[n][m]);} return 0;}
0 0
- Uva-1625-Color Length
- UVA 1625 Color Length
- UVA-1625 Color Length
- uva 1625 color length
- UVA 1625 Color Length
- UVA 1625 Color Length
- UVA 1625 Color Length
- UVa 1625 Color Length
- UVA 1625 Color Length
- UVA 1625 Color Length
- Color Length - UVa 1625 dp
- UVa OJ 1625 - Color Length
- uva 1625 Color Length (dp)
- UVa #1625 Color Length (例题9-8)
- UVA 1625 Color Length (DP)
- UVa 1625:Color Length(DP)
- uva 1625——Color Length
- Color Length UVA
- 手把手生成决策树(dicision tree)
- 蓝牙基带 包结构
- TCP传输协议中的Server和Cilent之间的交互
- 我的微信公众号
- dos命令行输入adb shell命令为什么报错
- UVa 1625 Color Length
- POJ 1125 (经典水题 floyd)
- TKT中文编程语言简介
- (总结)Nginx配置文件nginx.conf中文详解
- mysql的查询、子查询及连接查询
- 杨辉三角
- android studio下aidl的使用
- SLF4J分析
- IOS 监测网络状态