Tiling Up Blocks (LIS)
来源:互联网 发布:网络计划图绘制方法 编辑:程序博客网 时间:2024/05/20 18:52
Tiling Up Blocks
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 5300 Accepted: 2073
Description
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:
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.
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.
Input
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.
Output
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.
Sample Input
33 21 12 354 22 43 31 15 50
Sample Output
23*
Source
Asia Kaohsiung 2003
题目意思:你有n个积木 (L,W) 要问你最高能累多高
用最长不递增子序列 ok
题目意思:你有n个积木 (L,W) 要问你最高能累多高
用最长不递增子序列 ok
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>using namespace std;struct knob{ int l,w;}p[10005];int cmp(knob a,knob b){ return a.l==b.l ? (a.w>b.w) : (a.l>b.l);}int dp[10005];int main(){ int n; while(~scanf("%d",&n),n) { for(int i=1;i<=n;i++) { scanf("%d%d",&p[i].l,&p[i].w); } sort(p+1,p+1+n,cmp); memset(dp,0,sizeof(dp)); int ans = 1; for(int i=1;i<=n;i++) { dp[i]=1; for(int j=1;j<i;j++) { if(p[i].l<=p[j].l&&p[i].w<=p[j].w) { dp[i]=max(dp[i],dp[j]+1); } } ans = max(dp[i],ans); } printf("%d\n",ans); } printf("*\n");}
0 0
- Tiling Up Blocks (LIS)
- poj1609 Tiling Up Blocks(LIS)
- Poj 1609 Tiling Up Blocks (LIS--可以相等)
- pku1609 Tiling Up Blocks
- poj1609 Tiling Up Blocks
- POJ1609 Tiling Up Blocks
- poj1609 Tiling Up Blocks
- poj 1609 Tiling Up Blocks
- POJ 1609 Tiling Up Blocks.
- POJ1609:Tiling Up Blocks(DP)
- poj 1609 Tiling Up Blocks
- 1609 Tiling Up Blocks 解题报告
- pku1609 Tiling Up Blocks (DP题)
- poj 1609 Tiling Up Blocks 动态规划
- poj1609 - Tiling Up Blocks(动归)
- Tiling Up Blocks - POJ 1609 dp
- poj1609——Tiling Up Blocks
- poj 1609 Tiling Up Blocks(DP)
- IT技术创业的方向
- 文章标题
- placement new 的使用实例
- Category
- How to create a HTTP adapter in IBM Worlight
- Tiling Up Blocks (LIS)
- HDU3172 Virtual Friends
- C++ primer 读书笔记(第2章)变量和基本类型
- [联赛可能考到]图论相关算法——COGS——联赛试题预测
- 大整数乘法
- 使用GTest对项目进行单元测试
- 从无头单链表中删除节点
- Studio 自动导入包
- AngularJs轻松入门(九)与服务器交互