Problem Description
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.
Input
Input contains data for a bunch of mice, one mouse per line, terminated by end of file.
The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information for at most 1000 mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information for at most 1000 mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
Output
Your program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing a mouse). If these n integers are m[1], m[2],..., m[n] then it must be the case that
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[n]]
In order for the answer to be correct, n should be as large as possible.
All inequalities are strict: weights must be strictly increasing, and speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[n]]
In order for the answer to be correct, n should be as large as possible.
All inequalities are strict: weights must be strictly increasing, and speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
Sample Input
6008 1300 6000 2100 500 2000 1000 4000 1100 3000 6000 2000 8000 1400 6000 1200 2000 1900
Sample Output
4 4 5 9 7
/*
这题其实就是super jump jump jump的变形啊
题目要我们用最长的序列
这个序列满足总量在增大,而速度在减小。都是严格的
我们可以先按重量从小到大排序,速度从大到小排序
然后dp[i]表示以i结尾的满足要求的最长的序列
老鼠最多1000只,重量和速度都在10000内。
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Mice
{
int w,v;//重量和速度
int id;
}mice[1008];
int luxian[1008];
int pre[1008];
bool cmp(Mice a,Mice b)
{
if(a.w>b.w)return 0;
if(a.w<b.w)return 1;
if(a.w==b.w)
{
return a.v>b.v;
}
}
inline int max(int a,int b)
{
return a>b?a:b;
}
int dp[1008];
int main()
{
int t=0;
while(scanf("%d%d",&mice[t].w,&mice[t].v)==2)
{
mice[t].id=t+1;
t++;
}
sort(mice,mice+t,cmp);
//老鼠已经按重量从小到大,速度从大到小排序
//接着就是super jump jump jump 的问题了
dp[0]=1;
for(int i=1;i<t;i++)
{
int temp=1;
for(int j=0;j<i;j++)
{
if(mice[j].w<mice[i].w&&mice[j].v>mice[i].v)
{
if(dp[j]+1>=temp)
{
temp=dp[j]+1;
pre[mice[i].id]=mice[j].id;
}
}
}
dp[i]=temp;
}
int ans=0,wei;
for(int i=0;i<t;i++)
{
if(dp[i]>=ans)
{
ans=dp[i];
wei=mice[i].id;
}
}
printf("%d\n",ans);
t=0;
luxian[ans]=wei;
int zz=ans;
while (--ans)
{
luxian[ans]=pre[wei];
wei=pre[wei];
}
for(int i=1;i<=zz;i++)
{
printf("%d\n",luxian[i]);
}
return 0;
}