Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1160
Fatmouse ' s speedTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 9965 Accepted Submission (s): 4427
Special Judge
Problem Descriptionfatmouse believes, the 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.
Inputinput contains data for a bunch of 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.
Outputyour 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 13006000 2100500 20001000 40001100 30006000 20008000 14006000 12002000 1900
Sample Output
44597
Longest ascending subsequence and record path
#include <stdio.h> #include <iostream> #include <math.h> #include <stdlib.h> #include < ctype.h> #include <algorithm> #include <vector> #include <string> #include <queue> #include <stack> #include <set> #include <map>using namespace std;struct node{int x, y, num;} P[10010];bool CMP (Node A, Node B) {return a.x < b.x;} int pre[10010], dp[10010];vector<int> q;int main () {int x, Y;int len = 1;while (scanf ("%d%d", &x,&y)!=eof)// for (int i = 1; i < i++) {//cin >> x >> y;p[len].x = x;p[len].y = Y;p[len].num = len;len++;} Sort (p+1,p+len,cmp), memset (pre,0,sizeof (pre)), for (int i = 1; i < Len; i++) {Dp[i] = 1;for (int j = 1; j < I; J + +) {if (p[i].x > p[j].x && p[i].y < P[J].Y) {if (Dp[i] < dp[j] + 1) {Dp[i] = Dp[j] + 1;pre[p[i].num] = P[j].num;}}}} int ans =-1, num = 1;for (int i = 1; i < Len; i++) {if (ans < dp[i]) {ans = Dp[i];num = P[i].num;}} printf ("%d\n", ans); Q.clear (); while (num! = 0) {Q.pusH_back (num); num = Pre[num];} Reverse (Q.begin (), Q.end ()), for (int i = 0; i < q.size (); i++) printf ("%d\n", Q[i]); return 0;}
hdu-1160 Fatmouse ' s speed "longest ascending subsequence"