HDU 1160 FatMouse's Speed(DP)

来源:互联网 发布:淘宝刷手是什么意思 编辑:程序博客网 时间:2024/04/24 21:23

//#pragma commmpnt(linkmpr, "/STACK:102400000,102400000")#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>#include <queue>using namespace std;typedef long long LL;const int M = 100010;const int INF =0x3f3f3f3f;const int MAXN = 200050;struct node{    int w,s;    int num;    bool operator <(const node &b)const    {        if(w!=b.w)            return w<b.w;        else        {            return s>b.s;        }    }}a[1050];int dp[1050];int p[1050];int f[1050];int main(){    int cnt=1;    memset(dp,0,sizeof(dp));    memset(p,0,sizeof(p));    while(~scanf("%d%d",&a[cnt].w,&a[cnt].s))    {        a[cnt].num=cnt++;    }    sort(a,a+cnt);    int maxlen=0;    int pos=0;    dp[0]=1;    for(int i=1;i<cnt;++i)    {        for(int j=1;j<cnt;++j)        {            if(a[j].w<a[i].w && a[i].s<a[j].s && dp[j]+1>dp[i] )            {                dp[i]=dp[j]+1;                p[i]=j;                if(dp[i]>maxlen)                {                    pos=i;                    maxlen=dp[i];                }            }        }    }    int t=pos;    cnt=0;    while(t!=0)    {        f[cnt++]=t;        t=p[t];    }    printf("%d\n",cnt);    while(cnt>0)    {        cnt--;        printf("%d\n",a[f[cnt]].num);    }    return 0;    }



0 0
原创粉丝点击