Light oj 1110 LCS带打印路径
来源:互联网 发布:java sha1解密 编辑:程序博客网 时间:2024/04/26 07:23
这个LCS打印路径用string类最方便感觉!!!
#include<cstring>#include<cstdio>#include<iostream>#include<cmath>#include<algorithm>#include<queue>#include<vector>using namespace std;#define mod 1000000007#define PI acos(-1.0)#define INF 0x3f3f3f3ftypedef long long LL;int n,lena,lenb;int dp[105][105];int path[105][105];char a[105],b[105];void print_path(int x,int y){ if(x==0||y==0)return ; else if(path[x][y]==0){ print_path(x-1,y-1); printf("%c",a[x-1]); } else if(path[x][y]==1){ print_path(x-1,y); } else { print_path(x,y-1); }}int main(){ scanf("%d",&n); for(int k=1;k<=n;k++){ scanf("%s%s",a,b); lena=strlen(a); lenb=strlen(b); memset(dp,0,sizeof(dp)); memset(path,0,sizeof(path)); for(int i=1;i<=lena;i++){ for(int j=1;j<=lenb;j++){ if(a[i-1]==b[j-1]){ dp[i][j]=dp[i-1][j-1]+1; path[i][j]=0; } else if(dp[i-1][j]>dp[i][j-1]){ path[i][j]=1; dp[i][j]=dp[i-1][j]; } else { path[i][j]=-1; dp[i][j]=dp[i][j-1]; } } } printf("Case %d: ",k); if(dp[lena][lenb]==0)printf(":("); else print_path(lena,lenb); printf("\n\n"); } return 0;}
0 0
- Light oj 1110 LCS带打印路径
- light oj 1110 LCS 记录路径
- Light OJ 1110 An Easy LCS (DP+路径记录)
- Light OJ 1110 - An Easy LCS (LCS+字典序最小路径记录)
- Light oj 1110 - An Easy LCS(LCS)
- light oj 1159 - Batman LCS
- light oj An Easy LCS
- light oj 1013 LCS 应用
- Pku oj 2250 Compromise(LCS+打印路径)
- Light oj 1159 - Batman(三维 LCS)
- Light OJ 1157 LCS Revisited (DP)
- light oj 1033 - Generating Palindromes (LCS)
- light oj 1033 - Generating Palindromes 【LCS】
- poj2250-打印单一LCS路径。
- Light OJ 1013 - Love Calculator(LCS+ 计方案数)
- Light OJ:1033 Generating Palindromes(LCS+回文字符串)
- poj 2250 (LCS 需打印路径)
- poj1934-打印LCS全部路径+搜索
- 【HDU】-1237-简单计算器(栈)
- python 学习(六) for 循环语句
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator(概率DP)
- 如何推广和宣传网站?
- [16-7-25]每日总结
- Light oj 1110 LCS带打印路径
- Android性能优化
- apue源代码使用方法
- React学习----利用webpack搭建开发框架
- Exception in thread "main" java.lang.AbstractMethodError: weblogic.server.channels.ServerChannelImpl
- 2016-4-9 会议总结
- Hibernate学习笔记----Session管理和批量操作
- standupTimer项目中的状态恢复与保存
- 利用shell脚本遍历文件夹内所有的文件并作整理统计