UVa 10192 - Vacation
2014-03-12 22:51
344 查看
题目链接:UVa 10192 - Vacation
LCS。
LCS。
#include <iostream> #include <stdio.h> #include <cstring> using namespace std; const int MAX_N = 100 + 10; int dp[MAX_N][MAX_N]; char a[MAX_N],b[MAX_N]; int main() { int num = 0; while(gets(a) && a[0] != '#') { gets(b); int len1 = strlen(a); int len2 = strlen(b); for(int i = 0;i <= len1;i++) dp[i][0] = 0; for(int i = 1;i <= len2;i++) dp[0][i] = 0; for(int i = 1;i <= len1;i++) { for(int j = 1;j <= len2;j++) { if(a[i - 1] == b[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1; else dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]); } } //if(dp[len1][len2] > 1) cout << "Case #" << ++num << ": you can visit at most " << dp[len1][len2] << " cities." << endl; /*else cout << "Case #" << ++num << ": you can visit at most " << dp[len1][len2] << " city." << endl;*/ } return 0; }
相关文章推荐
- UVA 10192 - Vacation
- UVA - 10192Vacation(LIS)
- UVA - 10192 Vacation
- uva 10192 - Vacation
- uva 10192 Vacation
- UVa 10192: Vacation
- uva 10192 Vacation(最长公共子序列)
- Vacation - UVa 10192 最长公共子序列
- UVA - 10192 Vacation(dp+最大公共子序列)
- UVa 10192 - Vacation
- uva 10192 Vacation
- uva 10192 - Vacation(LCS)
- uva10192 - Vacation(dp,lcs)
- UVa 10192 Vacation
- [动态规划]UVA10192 - Vacation
- UVa 10192 Vacation (最长公共子序列)
- 【解题报告】uva10192_Vacation(假期, dp, LCS)
- uva10192 - Vacation (dp 最长公共子序列)
- uva 10192 Vacation
- UVA 10192 - Vacation(最长公共子序列)