light oj An Easy LCS
来源:互联网 发布:东华软件同花顺 编辑:程序博客网 时间:2024/04/26 15:59
#include <stdio.h>#include <string.h>#define maxx 150char s1[maxx];char s2[maxx];int dp[maxx][maxx];char s[maxx][maxx][maxx];int main(){ int T; while( scanf("%d",&T)==1) { int cases=0; while(T--) {memset(dp,0,sizeof(dp));memset(s,0,sizeof(s)); int k; scanf("%s %s",s1+1,s2+1); int n=strlen (s1+1); int m=strlen (s2+1); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { if(s1[i]==s2[j]) { dp[i][j]=dp[i-1][j-1]+1; for(k=0;k<dp[i-1][j-1];k++) s[i][j][k]=s[i-1][j-1][k]; s[i][j][k]=s1[i]; } else { if(dp[i-1][j]>dp[i][j-1]) { dp[i][j]=dp[i-1][j]; strcpy(s[i][j],s[i-1][j]); } else if(dp[i][j-1]>dp[i-1][j]) { dp[i][j]=dp[i][j-1]; strcpy(s[i][j],s[i][j-1]); } else { dp[i][j]=dp[i-1][j]; if(strcmp(s[i-1][j],s[i][j-1])>0) strcpy(s[i][j],s[i][j-1]); else strcpy(s[i][j],s[i-1][j]); } } } //printf("%d\n",n); printf("Case %d: ",++cases); if(dp[n][m]==0) printf(":(\n"); else puts(s[n][m]); }}}
0 0
- light oj An Easy LCS
- Light oj 1110 - An Easy LCS(LCS)
- Light OJ 1110 An Easy LCS (DP+路径记录)
- Light OJ 1110 - An Easy LCS (LCS+字典序最小路径记录)
- light oj 1159 - Batman LCS
- light oj 1013 LCS 应用
- LightOj 1110 An Easy LCS
- LightOJ 1110 An Easy LCS
- LightOJ - 1110 An Easy LCS(LCS)
- light oj 1110 LCS 记录路径
- Light oj 1159 - Batman(三维 LCS)
- Light OJ 1157 LCS Revisited (DP)
- Light oj 1110 LCS带打印路径
- light oj 1033 - Generating Palindromes (LCS)
- light oj 1033 - Generating Palindromes 【LCS】
- LightOJ 1110 An Easy LCS--DP
- LightOJ 1110 An Easy LCS dp基础
- LightOJ 1110 An Easy LCS LCS路径输出
- 《圈子标签论》
- iOS基础 - 静态库
- sqlalchemy文档资料翻译(五)
- ubutu14.04 配置 libxml2
- STL vector中的max_size方法(29)
- light oj An Easy LCS
- 2014互联网公司招聘应届生薪资大起底
- 信号完整性研究系列--信号振铃是怎么产生的
- sqlalchemy文档资料翻译(六)
- Eclipse调试快捷键小结
- linux 开机启动服务和 chkconfig 使用方法
- 最流行的android组件大全
- 一个数值转化为二进制 位运算和位域
- AFNetwork 作用和用法详解