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.
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.
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
题目大意:有一些老鼠,给出了体重和奔跑的速度,让你按老鼠的体重从大到小,速度从大到小排序。然后按老鼠编号顺序输出编号要求是最多的排序。
思路就是最大上升子序列不过是要输出路径,按体重从小到大排序,然后找到最大的排序,输出v路径即可代码如下
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int N;
scanf("%d",&N);
while(N--)
{
int n;
scanf("%d",&n);
int a[1200],b[1200];
int i,j;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int m;scanf("%d",&m);
for(j=0;j<m;j++)
scanf("%d",&b[j]);
int dp[600]={0};
int maxx=-100;
for(i=0;i<n;i++)
{maxx=0;
for(j=0;j<m;j++)
{
if(a[i]==b[j])
dp[j]=maxx+1;
if(a[i]>b[j])
maxx=max(dp[j],maxx);
}
}
int ans=-100;
for(i=0;i<=m;i++)
ans=max(ans,dp[i]);
printf("%d\n",ans);
if(N!=0)
printf("\n");
}
return 0;
}