Problem Description Fatmouse believes that's fatter a mouse is, the faster it runs. To disprove this, want to take the data in a collection of mice and put as large a subset of this data as possible int o A sequence So, the weights is increasing, but the speeds is decreasing.
Input input contains data for a bunch in mice, one mouse per line, terminated by end of file.
The data for a particular mouse would consist of a pair of integers:the first representing its size in grams and the Secon D representing its speed in centimeters per second. Both integers is between 1 and 10000. The data in all test case would contain information for at most of the mice.
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 is m[1], m[2],..., M[n] Then it must is 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 is correct, n should be as large as possible.
All inequalities is strict:weights must is strictly increasing, and speeds must be strictly decreasing. There may is many correct outputs for a given input, and 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
LIS, note the track of the path and how many arrays are initialized
#include <cstdio> #include <cstdlib> #include <string.h> #include <string> #include <math.h&
Gt
#include <algorithm> #include <iostream> #include <queue> #include <stack> #include <map>
#include <set> using namespace std; struct node {int w,s,i;}
M[1010];
BOOL CMP (Node A, Node B) {return a.w>b.w;}
int dp[1010],pre[1010];
int i,j;
int main () {int n=0;
while (CIN>>M[N].W>>M[N].S) {m[n].i=n+1;
n++;
} sort (m,m+n,cmp);
Memset (Dp,1,sizeof (DP));
memset (pre,-1,sizeof (pre));
for (i=0;i<n;i++) {dp[i]=1;
Pre[i]=-1;
} int midx=0; for (i=1;i<n;i++) for (j=0;j<i;j++) if (m[i].w<m[j].w && m[i].s>m[j].s && dp[j]+1>d
P[i]) {dp[i]=dp[j]+1;
Pre[i]=j;
if (Dp[i]>dp[midx]) midx=i;
} cout<<dp[midx]<<endl; while (midx!=-1) {cout<<m[midx].i<<endl;
MIDX=PRE[MIDX];
} return 0;
}