UVa #10723 Cyborg Genes (习题9-6)
来源:互联网 发布:access数据库 工具 编辑:程序博客网 时间:2024/06/05 14:29
最长公共子序列模型。
不同的解出现于d[i-1][j] == d[i][j-1]
不同的解出现于d[i-1][j] == d[i][j-1]
Run TIme: 0.009s
#define UVa "9-6.10723.cpp" //Cyborg Genes#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>using namespace std;int main() { const int maxn = 30+5; int T, n1, n2; scanf("%d", &T); getchar(); for(int kase = 1; kase <= T; kase ++) { int d[maxn][maxn]; int cnt[maxn][maxn]; string str1, str2; getline(cin, str1); getline(cin, str2); n1 = str1.length(); n2 = str2.length(); for(int i = 0; i <= n1; i ++) { d[i][0] = 0; cnt[i][0] = 1; } for(int j = 0; j <= n2; j ++) { d[0][j] = 0; cnt[0][j] = 1; } for(int i = 1; i <= n1; i ++) { for(int j = 1; j <= n2; j ++) { int& u = d[i][j], &uc = cnt[i][j]; if(str1[i-1] == str2[j-1]) { u = d[i-1][j-1] + 1; uc = cnt[i-1][j-1]; } else { int a = d[i-1][j], b = d[i][j-1]; u = max(a, b); if(a > b) uc = cnt[i-1][j]; else if(a < b) uc = cnt[i][j-1]; else uc = cnt[i-1][j] + cnt[i][j-1]; } } } printf("Case #%d: %d %d\n", kase, n1+n2-d[n1][n2], cnt[n1][n2]); } return 0;}
0 0
- UVa #10723 Cyborg Genes (习题9-6)
- uva 10723 Cyborg Genes
- UVA 10723 Cyborg Genes
- UVA 10723 Cyborg Genes
- uva 10723 Cyborg Genes
- UVA - 10723 Cyborg Genes
- UVa 10723 - Cyborg Genes
- uva 10723 - Cyborg Genes
- UVa 10723 Cyborg Genes
- UVA - 10723 Cyborg Genes
- UVA 10723 Cyborg Genes
- UVA 10723 Cyborg Genes
- uva 10723 Cyborg Genes
- UVa 10723 - Cyborg Genes LCS
- uva 10723 - Cyborg Genes(LIS)
- Cyborg Genes - UVa 10723 dp
- UVA 10723 Cyborg Genes(LCS)
- UVA - 10723 Cyborg Genes LCS变异版
- 拥抱Android:编译python搭建移动的无线服务器平台
- Java.util.concurrent包学习(三)BlockingQueue
- Yii----源码追踪
- ffmpeg解码中碰到的问题
- 微信公众平台开发(一)配置接口
- UVa #10723 Cyborg Genes (习题9-6)
- 树莓派自动连WiFi及启用远程桌面
- GitHub是如何征服Google、微软和其它公司的
- Coderforces 396A
- 通过U盘安装Fedora21 Workstation
- iOS UICollectionView 入门 04 使用UICollectionView的准备工作
- 使用Openssl的AES加密算法
- brief note on Makefile
- 记一次谈判实践