NUC1776 Tiling Up Blocks【二维最长上升子序列+DP】
来源:互联网 发布:邮币卡抢单软件 编辑:程序博客网 时间:2024/06/07 19:48
Tiling Up Blocks
时间限制: 1000ms 内存限制: 10000KB
通过次数: 2总提交次数: 2
问题描述
Michael The Kid receives an interesting game set from his grandparent as his birthday gift. Inside the game set box, there are n tiling blocks and each block has a form as follows:
Figure 1: Michael’s Tiling Block with parameters (3,2).
Each tiling block is associated with two parameters (l,m), meaning that the upper face of the block is packed with l protruding knobs on the left and m protruding knobs on the middle. Correspondingly, the bottom face of an (l,m)-block is carved with l caving dens on the left and m dens on the middle.
It is easily seen that an (l,m)-block can be tiled upon another (l,m)-block. However,this is not the only way for us to tile up the blocks. Actually, an (l,m)-block can be tiled upon another (l´,m´)-block if and only if l >= l´ and m >= m´.
Now the puzzle that Michael wants to solve is to decide what is the tallest tiling blocks he can make out of the given n blocks within his game box. In other words, you are given a collection of n blocks B = {b1, b2, . . . , bn} and each block bi is associated with two parameters (li,mi). The objective of the problem is to decide the number of tallest tiling blocks made from B.
Figure 1: Michael’s Tiling Block with parameters (3,2).
Each tiling block is associated with two parameters (l,m), meaning that the upper face of the block is packed with l protruding knobs on the left and m protruding knobs on the middle. Correspondingly, the bottom face of an (l,m)-block is carved with l caving dens on the left and m dens on the middle.
It is easily seen that an (l,m)-block can be tiled upon another (l,m)-block. However,this is not the only way for us to tile up the blocks. Actually, an (l,m)-block can be tiled upon another (l´,m´)-block if and only if l >= l´ and m >= m´.
Now the puzzle that Michael wants to solve is to decide what is the tallest tiling blocks he can make out of the given n blocks within his game box. In other words, you are given a collection of n blocks B = {b1, b2, . . . , bn} and each block bi is associated with two parameters (li,mi). The objective of the problem is to decide the number of tallest tiling blocks made from B.
输入描述
Several sets of tiling blocks. The inputs are just a list of integers.For each set of tiling blocks, the first integer n represents the number of blocks within the game box. Following n, there will be n lines specifying parameters of blocks in B; each line contains exactly two integers, representing left and middle parameters of the i-th block, namely, li and mi. In other words, a game box is just a collection of n blocks B = {b1, b2, . . . , bn} and each block bi is associated with two parameters (li,mi).
Note that n can be as large as 10000 and li and mi are in the range from 1 to 100.
An integer n = 0 (zero) signifies the end of input.
Note that n can be as large as 10000 and li and mi are in the range from 1 to 100.
An integer n = 0 (zero) signifies the end of input.
输出描述
For each set of tiling blocks B, output the number of the tallest tiling blocks can be made out of B. Output a single star ´*´ to signify the end of
outputs.
outputs.
样例输入
33 21 12 354 22 43 31 15 50
样例输出
23*
来源
Asia Kaohsiung 2003
问题分析:(略)
这个问题和《POJ1609 UVALive2815 UVA1196 ZOJ1787 Tiling Up Blocks【二维最长上升子序列+DP】》是同一个问题,代码直接用就AC了。
程序说明:参见参考链接。
参考链接:POJ1609 UVALive2815 UVA1196 ZOJ1787 Tiling Up Blocks【二维最长上升子序列+DP】
题记:程序做多了,不定哪天遇见似曾相识的。AC的C++程序如下:
/* POJ1609 UVALive2815 UVA1196 ZOJ1787 Tiling Up Blocks */#include <iostream>#include <stdio.h>#include <string.h>using namespace std;const int N = 100;int cnt[N+1][N+1], dp[N+1][N+1];int main(){ int n, left, mid; while(scanf("%d", &n) != EOF && n) { memset(cnt, 0, sizeof(cnt)); memset(dp, 0, sizeof(dp)); for(int i=0; i<n; i++) { scanf("%d%d", &left, &mid); cnt[left][mid]++; } // DP计算过程 for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) +cnt[i][j]; printf("%d\n", dp[N][N]); } printf("*\n"); return 0;}
阅读全文
0 0
- NUC1776 Tiling Up Blocks【二维最长上升子序列+DP】
- POJ1609 UVALive2815 UVA1196 ZOJ1787 Tiling Up Blocks【二维最长上升子序列+DP】
- hdu 1160 dp (二维最长上升子序列 记录路径
- 最长上升子序列 dp
- DP--最长上升子序列
- POJ1609:Tiling Up Blocks(DP)
- PKU2533 最长上升子序列 DP
- PKU1631 最长上升子序列 DP
- 最长上升子序列 (dp)
- 最长公共上升子序列 (dp)
- realoj 134 DP 最长上升子序列
- dp之最长上升子序列
- [DP]最长公共上升子序列LCIS
- 最长上升子序列(DP)
- [DP] OpenJudge 2757 最长上升子序列
- HDU1087(最长上升子序列DP)
- sdut1299最长上升子序列(dp入门)
- poj1631 dp 最长上升子序列LIS
- NUC1429 WERTYU【输入输出】
- Secdo response
- NUC1840 Graveyard Design【尺取法】
- 界面组件——按钮(Button)与图片按钮(ImageButton)
- Secdo observer
- NUC1776 Tiling Up Blocks【二维最长上升子序列+DP】
- 3、STM32联网驱动__接口方式_TCP/UDP协议栈_通信方式
- 利用Python实现基于Requests框架和多线程技术的Tumblr博客空间图片及视频下载
- 孩子兄弟表示法(二叉链表树) 时间 2014-06-02 16:32:17 CSDN博客 原文 http://blog.csdn.net/chdjj/article/details/2811164
- HTML5-video、audio标签
- C++输入重定向
- springMvc+spring4+maybatis简单例子
- Redis的高可用技术方案
- 表单提交Erro: formSubmit.html:** Uncaught TypeError: Cannot set property 'action' of null解决