• 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
  • 相关阅读:
    使用pwn_deploy_chroot部署国赛pwn比赛题目
    《Java程序设计》第十一章 JDBC与MySQL数据库
    使用commons.cli实现MyCP
    2018-2019-2 20175211 实验二《Java面向对象程序设计》实验报告
    结对编程练习_四则运算(第二周)
    20175211 2018-2019-2 《Java程序设计》第六周学习总结
    20175211 2017-2018-2 《Java程序设计》第六周学习记录(2)
    海思Hi35xx平台调试笔记
    ffmpeg,rtmpdump和nginx rtmp实现录屏,直播和录制
    文件传输(xmodem协议)
  • 原文地址:https://www.cnblogs.com/zhangchengbing/p/3233479.html
Copyright © 2020-2023  润新知