uva 10066 The Twin Towers(动态规划:LCS)
2014-09-06 15:12
411 查看
水题一道
代码如下:
代码如下:
#include <cstdio> #include <cstring> #include <algorithm> #define MAXN 110 using namespace std; int a[MAXN], b[MAXN]; int dp[MAXN][MAXN]; int main(void) { int len1, len2, t; t = 1; while(scanf("%d%d", &len1, &len2) && (len1||len2)) { for(int i=1; i<=len1; ++i) scanf("%d", &a[i]); for(int j=1; j<=len2; ++j) scanf("%d", &b[j]); memset(dp, 0, sizeof(dp)); for(int i=1; i<=len1; ++i) { for(int j=1; j<=len2; ++j) { if(a[i] == b[j]) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1); else dp[i][j] = max(dp[i-1][j], dp[i][j-1]); } } printf("Twin Towers #%d\nNumber of Tiles : %d\n\n", t++, dp[len1][len2]); } return 0; }
相关文章推荐
- uva 10066 - The Twin Towers(动态规划-最长公共子序列)
- UVa 10066 - The Twin Towers(LCS水题)
- UVA 10066 The Twin Towers 双塔 LCS,dp
- UVa 10066 - The Twin Towers(LCS水题)
- UVA - 10066 - The Twin Towers (动态规划, LCS)
- uva10066 - The Twin Towers(dp,lcs)
- UVA - 10066 The Twin Towers(LCS最长公共子序列)
- UVA 10066 The Twin Towers(LCS)
- uva10066 - The Twin Towers(LCS)
- UVA 10066 The Twin Towers LCS ,Commencel
- 【解题报告】uva10066_The Twin Towers(双塔, dp, LCS)
- UVA 10066 The Twin Towers (LCS)
- UVa 10192 - Vacation & UVa 10066 The Twin Towers ( LCS 最长公共子串)
- UVa 10192 - Vacation & UVa 10066 The Twin Towers ( LCS 最长公共子串)
- uva 10066 - The Twin Towers(LCS)
- uva 111 History Grading(动态规划:LCS)
- UVA - 10066 The Twin Towers(dp+最大公共子序列)
- UVA 10066 - The Twin Towers(最长公共子序)
- UVA 10066 The Twin Towers
- acm动态规划之LCS最长公共子串uva10405Longest Common Subsequence解题报告