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;
}
解题思路: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;
}
相关文章推荐
- UVa:10192 Vacation
- UVA - 10192 Vacation(dp+最大公共子序列)
- UVA - 10192 - Vacation (动态规划, LCS)
- UVA-10192-Vacation
- UVa 10192 - Vacation & UVa 10066 The Twin Towers ( LCS 最长公共子串)
- uva_10192 Vacation
- UVa 10192 - Vacation
- UVa 10192 - Vacation 字符串dp
- UVA 10192 - Vacation
- UVa 10192 Vacation (最长公共子序列)
- UVa 10192 - Vacation
- UVa 10192 - Vacation 字符串dp
- 判断条件UVa 10192 - Vacation(LCS水题)
- UVa 10192 Vacation (DP&LCS)
- UVA 10192 Vacation(dp + LCS)
- UVA 10192 Vacation
- UVa 10192 - Vacation
- UVa 10192 Vacation (DP 最长公共子序列)
- UVA 10192 Vacation 最长公共子序列(DP)
- UVa 10192: Vacation