您的位置:首页 > 其它

UVA - 10192 Vacation

2014-11-15 11:38 369 查看
题目大意:求两个字符串的最长公共子序列

解题思路:dp 状态转移方程

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
char A[105], B[105];
int t = 0;
while (gets(A) && A[0] != '#') {
gets(B);
int n = strlen(A);
int m = strlen(B);
int DP[105][105] = {0};

for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (A[i-1] == B[j-1])
DP[i][j] = DP[i-1][j-1] + 1;
else
DP[i][j] = max(DP[i][j-1], DP[i-1][j]);

printf("Case #%d: you can visit at most %d cities.\n", ++t, DP
[m]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: