D - Mysterious Present

来源:互联网 发布:c 可视化编程 编辑:程序博客网 时间:2024/05/21 09:02
D - Mysterious Present
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status

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 nwh (1  ≤ n ≤ 50001 ≤ 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 12 22 2
Output
11 
Input
3 3 35 412 119 8
Output
31 3 2 
#include<iostream>#include <map>#include <set>#include <list>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <vector>#include <bitset>#include <cstdio>#include <string>#include <numeric>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>#include <functional>using namespace std;typedef long long ll;#define Exp 1e-8#define inf 0x7fffffff#define Read freopen("in.txt","r",stdin)#define Write freopen("out.txt","w",stdout)#define maxn 55#define mod 1000000007struct Chain{    int w,h;    int id;} c[maxn];//储存每一个信封int dp[maxn]; //要用到最长上升子序列的dp方法int head[maxn];//排序后的第i个信封的前导,记录路径的作用int n,w,h;int cmp(Chain a,Chain b)//让所有信封按照长,宽的优先级从小到大排列{    if(a.w==b.w)        return a.h<b.h;    else        return a.w<b.w;}void read(){    scanf("%d%d%d",&n,&w,&h);    for(int i=0; i<n; i++)    {        scanf("%d%d",&c[i].w,&c[i].h);        c[i].id=i;//记录每封信封的初始位置    }    sort(c,c+n,cmp);//排序信封}void Dp(){    memset(dp,-1,sizeof(dp));    memset(head,-1,sizeof(head));    int flag=0;    for(int i=n-1; i>=0; i--)//检查是否存在信封能够实现信封套装    {        if(c[i].w>w&&c[i].h>h)        {            flag=1;            dp[i]=1;        }    }    if(flag==0)//没有,输出0,结束    {        printf("0\n");        return ;    }    for(int j=0; j<n; j++)//存在,求最长上升序列的长度    {        if(dp[j]==-1)//凡是dp=-1的,是无法装所给的信封的            continue;        for(int k=0; k<j; k++)        {            if(dp[k]==-1)                continue;            if(c[j].w>c[k].w&&c[j].h>c[k].h)                if(dp[k]+1>dp[j])                {                    head[j]=k;//记录路径,但这里是排序后的信封的路径,不过,有id这个属性                    dp[j]=dp[k]+1;                }        }    }    int maxdp=0,last=0;    for(int j=0; j<n; j++)        if(dp[j]>maxdp)//找到dp的最大值,就是最多嵌套数量        {            maxdp=dp[j];            last=j;        }    int path[maxn]={0},l=0;    while(last!=-1)//根据head数组,将路径还原    {        path[l]=c[last].id;        l++;        last=head[last];    }    printf("%d\n",maxdp);    for(int i=l-1;i>0;i--)//输出        printf("%d ",path[i]+1);    printf("%d\n",path[0]+1);}int main(){    read();    Dp();    return 0;}