HDU 1160 FatMouse's Speed

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1160

#include <iostream>
#include <algorithm>
using namespace std;

struct DP
{
    int w;
    int s;
    int len;
    int index;
    int parent;
};
bool cmp(const DP&a,const DP&b)
{
    if(a.w==b.w)
        return a.s>b.s;
    else return a.w<b.w;
}

void mycout(int idx,DP d[])
{
    if(d[idx].parent!=0)
        mycout(d[idx].parent,d);
    cout<<d[idx].index<<endl;
}

int main(int argc, const char *argv[])
{
    //freopen("input.txt","r",stdin);
    int l=1;
    DP dp[10001];
    while(cin>>dp[l].w>>dp[l].s)
    {
        dp[l].index=l;
        dp[l].parent=0;
        dp[l].len=0;
        l++;
    }
    sort(dp+1,dp+l,cmp);
    //for (int k = 1; k < i; k++)
    //{
    //    printf("%5d%5d\n",dp[k].w,dp[k].s);
    //}
    int max_len=0;
    int last_idx=0;
    for(int i=1;i<l;i++)
    {
        //printf("考虑第%d个,%5d%5d\n",i,dp[i].w,dp[i].s);
        for(int j=1;j<i;j++)
        {
            if(dp[j].len+1>dp[i].len&&dp[i].w>dp[j].w&&dp[i].s<dp[j].s)
            {
                    
                dp[i].len=dp[j].len+1;
                dp[i].parent=j;    
                //printf("     更新第%d个,%5d%5d%5d\n",i,dp[i].len,dp[i].w,dp[i].s);
                if(dp[i].len>=max_len)
                {
                    max_len = dp[i].len;
                    last_idx = i;
                }
            }
        }
    }

    cout<<max_len+1<<endl;
    mycout(last_idx,dp);
    return 0;
}

 

posted @ 2013-09-21 21:17  Destino74  阅读(162)  评论(0编辑  收藏  举报