POJ1609:Tiling Up Blocks(DP)

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
*

Source

Asia Kaohsiung 2003

题意:有几个积木,每个积木上面有凸起,下面有凹进去的部分,左边凸起与凹进去的个数都一样,是L,中间也一样,是M

对应的两个金木能堆起来,当且仅当L1>=L2&&M1>=M2,问最多能堆多高

思路,简单DP,dp[i][j] = max(dp[i-1][j],dp[i][j-1])+cnt[i][j];

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define ls 2*i
#define rs 2*i+1
#define up(i,x,y) for(i=x;i<=y;i++)
#define down(i,x,y) for(i=x;i>=y;i--)
#define mem(a,x) memset(a,x,sizeof(a))
#define w(a) while(a)
#define LL long long
const double pi = acos(-1.0);
#define Len 200005
#define mod 19999997
const int INF = 0x3f3f3f3f;

int dp[105][105];
int cnt[105][105];
int n,x,y,i,j,k;

int main()
{
    w(~scanf("%d",&n)&&n)
    {
        mem(dp,0);
        mem(cnt,0);
        up(i,0,n-1)
        {
            scanf("%d%d",&x,&y);
            cnt[x][y]++;
        }
        up(i,1,100)
        {
            up(j,1,100)
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])+cnt[i][j];
        }
        printf("%d\n",dp[100][100]);
    }
    printf("*\n");

    return 0;
}
时间: 2024-08-29 15:21:59

POJ1609:Tiling Up Blocks(DP)的相关文章

POJ1609 Tiling Up Blocks

无情的一题!!! 读了半小时题,才把题目看懂,发现是LIS后写了二分的那种方法,node[i]向ans[i]赋值的时候len++了两次,样例跑不出来,从机房走出去看见一只小猫,回来就发现了bug =.= 结果一提交,RE,检查发现n最大10000我开的22222,没开小,百度里面看到有人也用这个方法提交后也是RE...自己出了几组数据后发现貌似不能用二分写呢(至少我还没想到该怎么改,看到后知道怎么改的筒子请私信=.=) 下面是RE二分代码 #include <iostream> #includ

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

[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. I

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

uva 11270 - Tiling Dominoes(插头dp)

题目链接:uva 11270 - Tiling Dominoes 题目大意:用1?2木块将给出的n?m大小的矩阵填满的方法总数. 解题思路:插头dp的裸题,dp[i][s]表示第i块位置,并且该位置对应的行数的状态为s的时候的总情况数.0表示为竖放预留留的位置,1表示填上的位置,不管是竖放还是横放.并且第一位状态用滚动数组优化空间. #include <cstdio> #include <cstring> #include <algorithm> using names

poj 2663 Tri Tiling 状压dp

题意: 给3*N(N<=30)的矩形,问有多少种用1*2的小矩形铺满的方案. 分析: 同poj2411. 代码: #include <iostream> using namespace std; __int64 ans[32][4]; int n,m; __int64 dp[2][1<<4]; __int64 solve() { int i,j,used; memset(dp,0,sizeof(dp)); __int64 *crt=dp[0],*nxt=dp[1]; crt[

poj 3420 Quad Tiling 状压dp

题意: 给4*n(n<10^9)的大矩形,问有多少种用1*2的小矩形填满的方案. 分析: 又是铺瓷砖,不过这次n太大,不能再一个一个格的dp了.可以先算出相邻两行的状态转移,再用矩阵来加速n行的状态转移. 代码: //poj 3420 //sep9 #include <iostream> using namespace std; const int maxN=16; struct MATRIX { __int64 m[maxN][maxN]; }mat; int n,mod; void

POJ 3420 Quad Tiling 状压DP+矩阵快速幂

链接:http://poj.org/problem?id=3420 题意:给一个4*N(1 ≤ N ≤ 1e9)的矩形空间,并且给不限块数的1*2的多米诺骨牌,问是由多少种方式能把这个矩形空间填满. 思路:看到这种问题果断想到状压,虽然是在看矩阵的时候看到的这道题.dp[i][j]表示在第i行状态为j的情况下的填满方式数,j的二进制表示中0表示对应位置上一行的骨牌是竖放,或者对应位置的骨牌是横放,1则表示该行该位置的骨牌是竖放.由于N最大1e9所以O(n)的DP绝对超时,用矩阵快速幂来加速DP递

DP题目列表/弟屁专题

声明: 1.这份列表不是我原创的,放到这里便于自己浏览和查找题目. ※最近更新:Poj斜率优化题目 1180,2018,3709 列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887, 1926, 1936, 195