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
  • 相关阅读:
    EF Load之详讲
    WPF系列 自定控件
    EF6 的性能优化
    WPF系列 Path表示语法详解(Path之Data属性语法)
    WPFTookit Chart 高级进阶
    WPFTookit Chart 入门
    WPF系列-CheckBox
    WPF系列 Style
    ASP.NET MVC 5 with EF 6 上传文件
    WPF Prism
  • 原文地址:https://www.cnblogs.com/zhangchengbing/p/3233479.html
Copyright © 2011-2022 走看看