[2016-03-11][POJ][1609][Tiling Up Blocks]

[2016-03-11][POJ][1609][Tiling Up Blocks]

Tiling Up Blocks

Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u

Submit Status

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.

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.

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.

Sample Input

3
3 2
1 1
2 3
5
4 2
2 4
3 3
1 1
5 5
0

Sample Output

2
3
*


  • 时间:2016-03-11 19:11:31 星期五
  • 题目编号:POJ 1609 Tiling Up Blocks
  • 题目大意:给定一个积木,每个积木有参数(l,m)当且仅当一个积木的 l‘ <= l && m‘ <= m 时这个积木可以堆到(l,m)的积木上,给定一堆积木,问对多能堆多高
  • 输入:
      • 多组数据
      • 每组数据
      • n积木的数目
      • 接下来n行,每行两个数字,每个积木的参数
      • n==0表示结束
  • 输出:
        • 每组数据输出一行,每行一个数字表示最大的高度
        • 输入结束之后 输出 单独一行 * 表示结束
  • 分析:
      • 首先按l对积木排序,那么剩下的就是求最多能叠多高,这时候只需要对另外一个参数求最长非减子序列即可
  • 解题过程遇到问题:
      • dp忘记初始化




#include <vector>

#include <list>

#include <map>

#include <set>

#include <deque>

#include <queue>

#include <stack>

#include <bitset>

#include <algorithm>

#include <functional>

#include <numeric>

#include <utility>

#include <sstream>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cctype>

#include <string>

#include <cstring>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <ctime>

using namespace std;

typedef long long LL;

#define CLR(x,y) memset((x),(y),sizeof((x)))

#define FOR(x,y,z) for(int (x)=(y);(x)<(z);++(x))

#define FORD(x,y,z) for(int (x)=(y);(x)>=(z);--(x))

#define FOR2(x,y,z) int (x);for((x)=(y);(x)<(z);++(x))

#define FORD2(x,y,z) int (x);for((x)=(y);(x)>=(z);--(x))

typedef pair<int,int> Point;

#define x first

#define y second

const int maxn = 10000 + 10;

int dp[maxn];

Point a[maxn];

int main(){

//freopen("in.txt","r",stdin);

//freopen("out.txt","w",stdout);

int n;

while(~scanf("%d",&n) && n){

FOR(i,0,n){

scanf("%d%d",&a[i].x ,&a[i].y);

}

memset(dp,0,sizeof(dp));

sort(a,a+n);

CLR(dp,0);

FOR(i,0,n){

dp[i] = 1;

FOR(j,0,i){

if(a[i].y >= a[j].y){

dp[i] = max(dp[i],dp[j] + 1);

}

}

}

int ans = 0;

FOR(i,0,n){

ans = max(ans,dp[i]);

}

printf("%d\n",ans);

}

puts("*");

return 0;

}




来自为知笔记(Wiz)

时间: 2024-10-10 12:40:15

[2016-03-11][POJ][1609][Tiling Up Blocks]的相关文章

POJ 1609 Tiling Up Blocks.

~~~~ 二维的最长上升子序列.n^2算法居然可以水过.. 就不多说了,排个序,然后DP. 题目链接:http://poj.org/problem?id=1609 ~~~~ #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #define N 11111 using namespace std; struct node { int l,m; }b[N]; boo

poj 1609 Tiling Up Blocks dp入门之记忆化搜索

题意: 给n个二元组(a,b),要在其中找最长的序列,使得对序列中的任意i<j,有ai<=aj且bi<=bj. 分析: 设dp[a][b]代表以(a,b)结尾的最长序列长度,记忆化搜索即可. 代码: //poj 1609 //sep9 #include <iostream> using namespace std; const int max_p=128; int n; int num[max_p][max_p]; int dp[max_p][max_p]; int sear

Linux 学习笔记 2016.03.11

第一个简单命令: ls,就是查看当前工作路径下的文件都有哪些啦,常用的也就几个参数 1.ls -a 表示以字母表的顺序列出当前目录下面的文件. 2.ls -l 表示列出各个文件的详细信息,至于是什么详细信息,可以看下面的啦 ls -l(这个参数是字母L的小写,不是数字1) 这个命令可以使用长格式显示文件内容,如果需要察看更详细的文件资料,就要用到ls -l这个指令.例如我在某个目录下键入ls -l可能会显示如下信息(最上面两行是我自己加的): 位置 1 2 3 4 5 6 7 文件属性 文件数

分布式技术一周技术动态 2016.03.20

分布式系统实践 1. 基于Mesos和Docker的分布式计算平台 https://mp.weixin.qq.com/s?__biz=MzAxMDgzOTA2Mw==&mid=402769128&idx=1&sn=cea3ad1357bd9312acf1768c0a493bfd&scene=1&srcid=0318BTuxT0fsFYwPjpeyuDOa&key=710a5d99946419d90fbc1e7600cce055b6e997d6afafc74c

POJ 1052 Plato&#39;s Blocks

Plato's Blocks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 734   Accepted: 296 Description Plato believed what we perceive is but a shadow of reality. Recent archaeological excavations have uncovered evidence that this belief may hav

POJ 1609 二维递推

Tiling Up Blocks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5176   Accepted: 2028 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 bl

POJ 2506 -TILING

水题,一个小模拟,规律也好找 f3 = f1 * 2 + f2; #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <algorithm> const int INF = 1e8; const int N = 100; #define ll long long using namespace std; int a[251][N]

[野狐行][2016/04/11][群直播系列2][那些年让我们郁闷不已的游戏保护]

最近应广大朋友的建议,增加群内直播系列,主要内容包括不仅限于“辅助行业探讨,内幕揭秘,行业八卦”.每周周末,群内直播系列:1.2016/04/02 第一期下载地址: http://pan.baidu.com/s/1bpnwPeZ 2.2016/04/11 第二期下载地址: http://pan.baidu.com/s/1nvs22xj

2016/3/11 随笔一

最近开始找工作,也加了不少找工作的群,看见很多人在问我是二本的,在简历关会被筛吗.我在哪个 哪个方面比别人有劣势,我有希望吗?当看到某某三本的同学进了BAT,又焕发斗志,觉得自己也行,赶紧向别人取经.觉得自己好好努力也行了. 从这里我们可以抽象出一种人类某个方面的模型出来,大部分人只看到了自己的劣势,然后在进入任何组织的时候都会问,我这个方面有劣势,我会有机会吗.当看到同样在这个方面有劣势的或者比自己更差的人却成功的进入了某个热门组织的时候.又新生希望,在想那小子都进了,我肯定也没问题.但结果可