zoukankan      html  css  js  c++  java
  • 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 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

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 const int maxn=107;
     8 int dp[maxn][maxn];
     9 int num[maxn][maxn];
    10 int n;
    11 
    12 int main()
    13 {
    14   // freopen("in.txt","r",stdin);
    15     int a,b;
    16     while(~scanf("%d",&n)){
    17             if(n==0){
    18                 printf("*
    ");
    19                 break;
    20             }
    21         memset(dp,0,sizeof(dp));
    22         memset(num,0,sizeof(num));
    23         for(int i=0;i<n;i++)
    24         {
    25             scanf("%d%d",&a,&b);
    26             num[a][b]++;
    27         }
    28         for(int i=1;i<=100;i++)
    29             for(int j=1;j<=100;j++)
    30         {
    31             dp[i][j]=max(dp[i-1][j],dp[i][j-1])+num[i][j];
    32         }
    33         printf("%d
    ",dp[100][100]);
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    windows2012 永激活及配置
    Fiddler2 英文版翻译
    你知道using的用法吗?
    你会利用css写下拉列表框吗?
    完美解决.net2.0和.net4.0在同一个iis中共同运行
    深入剖析new override和virtual关键字
    思科防火墙,h3c三层交换机配置笔记
    c# 笔记 数据类型转换 数组 函数
    Silverlight 完美征程 笔记1 (控件模型)
    C#笔记(流程控制)
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4280039.html
Copyright © 2011-2022 走看看