zoukankan      html  css  js  c++  java
  • D

    Description

    Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1,  a2,  ...,  an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i  -  1)-th envelope respectively. Chain size is the number of envelopes in the chain.

    Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes.

    Peter has very many envelopes and very little time, this hard task is entrusted to you.

    Input

    The first line contains integers n, w, h (1  ≤ n ≤ 5000, 1 ≤ w,  h  ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi — width and height of the i-th envelope (1 ≤ wi,  hi ≤ 106).

    Output

    In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers.

    If the card does not fit into any of the envelopes, print number 0 in the single line.

    Sample Input

    Input
    2 1 1 
    2 2
    2 2
    Output
    1 
    1
    Input
    3 3 3 
    5 4
    12 11
    9 8
    Output
    3 
    1 3 2

    题意:

    AC代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<algorithm>
     5 
     6 using namespace std;
     7 struct xin
     8 {
     9     int a,b;
    10     int wei;
    11 }k[5010];
    12 int dp[5010]={0};
    13 int s[5010]={0};
    14 int cmp(xin a,xin b)
    15 {
    16     if(a.a==b.a) return a.b<b.b;
    17     else return a.a<b.a;
    18 
    19 }
    20 
    21 
    22 
    23 int main()
    24 {
    25     int n,i,j=0;
    26     int a,b;
    27     cin>>n>>a>>b;
    28     for(i=0;i<n;i++){
    29         cin>>k[j].a>>k[j].b;
    30         if(k[j].a>a&&k[j].b>b){k[j].wei=i+1;j++;}
    31     }
    32     if(j==0){cout<<0<<endl;return 0;}
    33     sort(k,k+j,cmp);
    34     n=j;
    35     int max=0;
    36     for(i=0;i<n;i++){
    37         max=0;
    38         for(j=0;j<i;j++)
    39             if(k[j].b<k[i].b&&k[j].a<k[i].a&&max<dp[j])max=dp[j];
    40         dp[i]=max+1;
    41     }
    42     max=0;
    43     for(i=0;i<n;i++)if(dp[i]>max)max=dp[i];
    44     cout<<max<<endl;
    45     i=-1;
    46     while(dp[++i]!=max){}
    47     int right=0;
    48     max--;
    49     s[right++]=k[i].wei;
    50     for(;max>0;max--){
    51             for(j=0;;j++){
    52                 if(dp[j]==max&&k[j].b<k[i].b&&k[j].a<k[i].a)break;
    53             }
    54             i=j;
    55         s[right++]=k[i].wei;
    56     }
    57     for(i=right-1;i>=0;i--)cout<<s[i]<<" ";
    58     cout<<endl;
    59     return 0;
    60 }
    View Code
  • 相关阅读:
    怎么使用 Jupyter Notebook 进入指定的目录
    安卓手机安装Xposed框架/钉钉虚拟定位
    Some of the Example google dorks 2019谷歌hacker语法检索表
    在心脏内部,普通的WEB用户会怎样? 心脏滴血漏洞分析学习
    Windows的安全配置基础,打造一个安全点的Windows
    计算机存储单位
    Python如何安装whl文件,python安装py包
    jdk文件中javaw的作用
    msfconsole基础使用,简洁高效学习版
    VirtualBox报错:不能为虚拟电脑XXX打开一个新任务
  • 原文地址:https://www.cnblogs.com/zhangchengbing/p/3233479.html
Copyright © 2011-2022 走看看