uva 10131

来源:互联网 发布:三国群英传mac版 编辑:程序博客网 时间:2024/06/04 18:57
paht[] 记录路径, 递归书写路径
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>using namespace std;#define MAXN 1100struct node{    int w, iq, id;    bool operator < ( const node &a) const    {        if(w != a.w)            return w < a.w;        return iq < a.iq;    }} ele[MAXN];int path[MAXN];int dp[MAXN], ans = -1;void outpath( int n){    if(ans--)    {        outpath(path[n]);        printf("%d\n",ele[n].id);    }};int main(){    int cnt = 1;    while(~scanf("%d %d",&ele[cnt].w, &ele[cnt].iq) )    {        ele[cnt].id = cnt;        cnt++;    }    cnt--;    for( int i = 1; i <= cnt; i++)    {        dp[i] = 1;        path[i] = i;    }    int  pos = 0;    sort(ele + 1, ele + cnt);//    for( int i = 0; i <= cnt; i++)//     printf("%d -> %d\n",ele[i].w, ele[i].iq);    for( int i = 1; i <= cnt; i++)    {        for( int j = 1; j < i; j++)        {            if(ele[i].w > ele[j].w && ele[i].iq < ele[j].iq && dp[i] < dp[j] + 1)            {                dp[i] = dp[j] + 1;                path[i] = j;            }        }        if(ans < dp[i])        {            ans = dp[i];            pos = i;        }    }    printf("%d\n",ans);    outpath(pos);}
0 0
原创粉丝点击