paht[] 记录路径, 递归书写路径
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define MAXN 1100
struct 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 = 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);
}