题意  输入n个老鼠的体重和速度   从里面找出最长的序列  是的重量递增时速度递减

简单的DP  令d[i]表示以第i个老鼠为所求序列最后一个时序列的长度  对与每一个老鼠i  遍历全部老鼠j  当(w[i] > w[j]) && (s[i] < s[j])时  有d[i]=max(d[i],d[j]+1)  输出路径记下最后一个递归即可了

#include<cstdio>
#include<algorithm>
using namespace std;
const int M=1005;
int w[M], s[M], d[M], pre[M], n, key; int dp (int i)
{
if (d[i] > 0) return d[i];
for (int j = d[i] = 1; j <= n; ++j)
if ( (w[i] > w[j]) && (s[i] < s[j]) && (d[i] < dp (j) + 1))
d[i] = d[j] + 1, pre[i] = j;
return d[i];
} void print (int i)
{
if (pre[i])
print (pre[i]);
printf ("%d\n", i);
} int main()
{
n = 0;
while (scanf ("%d %d", &w[n], &s[++n]) != EOF);
for (int i = key =1; i <= n; ++i)
if (dp (i) > dp (key)) key = i;
printf ("%d\n", d[key]);
print (key);
return 0;
}

FatMouse's Speed

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
 

最新文章

  1. poj 1733
  2. 跨平台C的IDE
  3. 单点登录(iwantmoon.com出品)
  4. Delphi反汇编内部字符串处理函数/过程不完全列表
  5. iOS异常捕获
  6. DX相机变换矩阵推导
  7. HTML 5 学习 (1)
  8. BZOJ 1684: [Usaco2005 Oct]Close Encounter
  9. libcurl模拟登录CSDN并自动评论资源以获取积分
  10. C语言指针声明探秘
  11. SRM340 VegetableGarden
  12. 【摘】Oracle 11g EM安全证书问题无法访问的解决办法
  13. java.net.NoRouteToHostException: No route to host解决方法
  14. IOS面试题2018/11/17
  15. java注解学习(1)注解的作用和三个常用java内置注解
  16. 关于Entity Framework的概念及搭建
  17. 20164317 《网络对抗技术》Exp6 信息搜集与漏洞扫描
  18. 在linux上执行.net Console apps
  19. startActivityForResult()的用法(超好用啊)
  20. [Erlang27]如何监控指定目录下的*.beam文件,如果有改动就更新到指定的节点?

热门文章

  1. SQL 中 NOT IN 查询不到数据
  2. 秋招复习-C++(三)
  3. 小而美的Promise库——promiz源码浅析
  4. pandas.read_csv 报ssl.SSLError
  5. python基础知识09-继承,多继承和魔术方法
  6. 杭电 1596 find the safest road (最小路径变形求最大安全度)
  7. ubuntu修改apt-get源为国内镜像源
  8. Vue如何在webpack设置代理解决跨域问题
  9. INFO main org.springframework.context.support.AbstractApplicationContext
  10. Git上传的使用步骤