UVA - 10066 The Twin Towers(LCS最长公共子序列)
2017-08-09 16:47
453 查看
题目大意:有两个塔,用类似的石头堆成,现在要求取出一部分石头使得两个塔完全相同,同时要求塔尽可能高,输出剩余石头数量
解题思路:LCS
解题思路:LCS
#include<iostream> #include<stdio.h> #include<algorithm> #include<cmath> #include<string.h> #include<string> #include<queue> #include<map> #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) const int INF = 0x3f3f3f3f; const int NINF = -INF -1; const int MAXN = 100+5; using namespace std; int n1, n2; int a[MAXN], b[MAXN]; int dp[MAXN][MAXN]; int main() { int T = 0; while (scanf("%d%d", &n1, &n2) && n1+n2) { for (int i = 0; i < n1; i++) scanf("%d", &a[i]); for (int i = 0; i < n2; i++) scanf("%d", &b[i]); memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n1; i++) for (int j = 1; j <= n2; 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]); printf("Twin Towers #%d\nNumber of Tiles : %d\n\n", ++T, dp[n1][n2]); } return 0; }
相关文章推荐
- UVa 10192 - Vacation & UVa 10066 The Twin Towers ( LCS 最长公共子串)
- UVA 10066 The Twin Towers 双塔 LCS,dp
- UVA 10066 The Twin Towers(LCS)
- uvaoj 10066 - The Twin Towers 最长公共子序列(LCS)
- UVA 10066 -The Twin Towers(最长公共子序列)
- uva 10066 The Twin Towers(动态规划:LCS)
- uva 10066 - The Twin Towers(LCS)
- uva10066 - 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(dp,lcs)
- UVA 10066 The Twin Towers (LCS)
- UVa 10192 - Vacation & UVa 10066 The Twin Towers ( LCS 最长公共子串)
- uva 10066 The Twin Towers (最长公共子序列)
- The Twin Towers - UVa 10066 最长公共子序列
- UVA 10066 The Twin Towers LCS ,Commencel
- UVa 10066 The Twin Towers(最长公共子序列)
- UVA - 10066 - The Twin Towers (动态规划, LCS)
- uva 10066 - The Twin Towers(动态规划-最长公共子序列)