博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 10066 - The Twin Towers(动态规划-最长公共子序列)
阅读量:4035 次
发布时间:2019-05-24

本文共 2866 字,大约阅读时间需要 9 分钟。

1、

2、题目大意,

有两座塔,每坐塔都有不同的层次组成,每层的半径也不相同,现在要将两座塔改造成完全相同的两座塔,要求高度一样,每层的半径也一样,保证塔层不变,问新塔的最高高度是多少?

最长公共子序列就可以做,不过错了一遍,注意每组样例之后都有一个空行

3、题目:

Problem B

The Twin Towers

Input: standard input

Output: standard output

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 circular tiles one upon another. Each of the tiles was of the same height and had integral radius. It is no wonder that though the two towers were of dissimilar shape, they had many tiles in common.

However, more than thousand years after they were built, the Emperor ordered his architects to remove some of the tiles from the two towers so that they have exactly the same shape and size, and at the same time remain as high as possible. The order of the tiles in the new towers must remain the same as they were in the original towers. The Emperor thought that, in this way the two towers might be able to stand as the symbol of harmony and equality between the two cities. He decided to name them the Twin Towers.

Now, about two thousand years later, you are challenged with an even simpler problem: given the descriptions of two dissimilar towers you are asked only to find out the number of tiles in the highest twin towers that can be built from them.

Input

The input file consists of several data blocks. Each data block describes a pair of towers.

The first line of a data block contains two integers N1 and N2 (1 <= N1, N2 <= 100) indicating the number of tiles respectively in the two towers. The next line contains N1 positive integers giving the radii of the tiles (from top to bottom) in the first tower. Then follows another line containing N2 integers giving the radii of the tiles (from top to bottom) in the second tower.

The input file terminates with two zeros for N1 and N2.

Output

For each pair of towers in the input first output the twin tower number followed by the number of tiles (in one tower) in the highest possible twin towers that can be built from them. Print a blank line after the output of each data set.

Sample Input

7 6

20 15 10 15 25 20 15
15 25 10 20 15 20
8 9
10 20 20 10 20 10 20 10
20 10 20 10 10 20 10 10 20
0 0

Sample Output

Twin Towers #1

Number of Tiles : 4
Twin Towers #2
Number of Tiles : 6

4、ac代码:

#include
#define N 105#include
using namespace std;int a[N];int b[N];int dp[N][N];int n,m;void DP(){ for(int i=0;i<=n;i++) { for(int j=0;j<=m;j++) { dp[i][j]=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-1][j],dp[i][j-1]); } }}int main(){ int cas=0; while(scanf("%d%d",&n,&m)!=EOF) { cas++; if(n==0 && m==0) break; for(int i=0;i

 

转载地址:http://sqddi.baihongyu.com/

你可能感兴趣的文章
web.xml配置加载顺序
查看>>
ServletContextListener使用详解
查看>>
UrlRewriteFilter使用说明
查看>>
java对redis的基本操作
查看>>
Java Math的 floor,round和ceil的使用
查看>>
通过url方式传递中文乱码解决办法
查看>>
Java的初始化机制、垃圾回收机制和内存分配机制
查看>>
MySQL5.6安装步骤(windows7/8_64位)
查看>>
FreeMarker基础配置
查看>>
Java中使用Jedis操作Redis
查看>>
Redis中常用命令
查看>>
spring下载
查看>>
读取request流
查看>>
微信消息模板的配置
查看>>
Spring框架结合Quartz实现任务调度实例
查看>>
Quartz Cron表达式 在线生成器
查看>>
struts2中action接收参数的3种方法
查看>>
java获取随机数
查看>>
url中传递中文参数时的转码与解码
查看>>
百度Ueditor设置允许上传的图片格式及大小
查看>>