FatMouse's Speed

Problem  Link:http://acm.hdu.edu.cn/showproblem.php?pid=1160

Original  Problem:


FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9284    Accepted Submission(s): 4125
Special Judge


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. 
 

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
 

Source
Zhejiang University Training Contest 2001

题意:给你许多组数据,没组两个数,一个代表老鼠的重量,一个代表老鼠的速度,为了证明老鼠越重速度越慢,让你取出几组数据证明,问最多能取出几组。体重要严格递增,速度严格递减。

 

这题是最长上升子序列问题,只是还需要输出其路线。我学会了DP记录路径^_^

code:
#include
#include
#include
using namespace std;
struct node{
	int w;
	int s;
	int no;
}mice[1111];
struct node1{
	int pre;
	int num;
}dp[1111];
bool cmp(node a,node b)
{
	if(a.w==b.w)
		return a.s>b.s;
	return a.wmice[j].s&&mice[k].wmax)
		{
			max=dp[j].num;
			t=j;
		}
	}
	printf("%d\n",max);
	int m[1111];
    for(j=1;j<=max;j++)
	{
		m[j]=t;
		t=dp[t].pre;
	}
	for(k=max;k>=1;k--)
		printf("%d\n",mice[m[k]].no);
	return 0;
}
总结经验:排序用sort,不要用qsort。调用sort函数须加头文件#include和using namespace  std;


你可能感兴趣的:(ACM,HDU,动态规划)