UVA 10066 The Twin Towers

DP,题目很长,题意就是求LCS。

#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<vector>
#include<cmath>

#define INF 0x7fffffff
#define eps 1e-8
#define LL long long
#define PI 3.141592654
#define CLR(a,b) memset(a,b,sizeof(a))
#define FOR(i,a,n) for(int i= a;i< n ;i++)
#define FOR0(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define sf scanf
#define pf printf
#define acfun std::ios::sync_with_stdio(false)

#define SIZE 100+1
using namespace std;

int a[SIZE],b[SIZE],dp[SIZE][SIZE];

int main()
{
    int la,lb;
    int ca=1;
    while(~sf("%d%d",&la,&lb),la||lb)
    {
        FOR(i,0,la)
        sf("%d",&a[i]);
        FOR(i,0,lb)
        sf("%d",&b[i]);

        CLR(dp,0);
        FOR(i,0,la)
        FOR(j,0,lb)
        {
            if(a[i]==b[j])
                dp[i+1][j+1]=dp[i][j]+1;
            else
                dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
        }
        pf("Twin Towers #%d\n",ca++);
        pf("Number of Tiles : %d\n\n",dp[la][lb]);
    }
}
时间: 2024-12-29 11:17:33

UVA 10066 The Twin Towers的相关文章

uva 10066 The Twin Towers (最长公共子)

uva 10066 The Twin Towers 标题效果:最长公共子. 解题思路:最长公共子. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; int a[105], b[105], dp[105][105]; int main() { int n, m, Case = 1; while (scanf(&quo

uva 10066 The Twin Towers (最长公共子序列)

uva 10066 The Twin Towers 题目大意:最长公共子序列. 解题思路:最长公共子序列. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; int a[105], b[105], dp[105][105]; int main() { int n, m, Case = 1; while (scanf(

UVa 10066 The Twin Towers(最长公共子序列)

The Twin Towers Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Description Once upon a time, in an ancient Empire, there were two towers of dissimilar shapes in two different cities. The towers were built by putting circula

UVa 10066 Twin Towers (DP 最长公共子序列)

题意  求两串数字最长公共子序列的长度 裸的lcs没啥说的 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=105; int a[maxn],b[maxn],d[maxn][maxn],na,nb; void lcs() { memset(d,0,sizeof(d)); for(int i=1; i<=na; ++i) for(in

UVA - 10066The Twin Towers(LIS)

题目:UVA - 10066The Twin Towers(LIS) 题目大意:求两个整数序列的最长公共子序列. 解题思路:和uva10405同样的思路.注意每组输出后面要输出空行,不然会WA. 代码: #include <cstdio> #include <cstring> const int N = 105; int s1[N], s2[N]; int l[N][N]; int l1, l2; void init () { memset (l, 0, sizeof (l));

uva 10066 lcs 水题

#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack> #include <climits> #include <cstring> #include <cmath> #include <map> #include <set> #define INF 10000

zoj2059 The Twin Towers (dp)

Description Twin towers we see you standing tall, though a building's lost our faith will never fall. Twin towers the world hears your call, though you're gone it only strengthens our resolve. We couldn't make it through this without you Lord, throug

LightOJ1126 Building Twin Towers(DP)

题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1126 Description Professor Sofdor Ali is fascinated about twin towers. So, in this problem you are working as his assistant, and you have to help him making a large twin towers. For this

uva--10066The Twin Towers +dp

其实就是求两个序列的最长公共子序列 代码如下: #include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int n1,n2,Case=0; while(scanf("%d%d",&n1,&n2)&&n1) { int a[110],b[110]; int dp[110][110],i,j; memse