FatMouse's Speed

Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge

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 Specification

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 Specification

Your program should output a sequence of lines of data; the first line should contain a numbern; the remainingn lines should each contain a single positive integer (each one representing a mouse). If thesen integers arem[1],m[2],...,m[n] then it must be the case that

  1. W[m[1]] < W[m[2]] < ... < W[m[n]]

and

  1. 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

  1. 6008 1300
  2. 6000 2100
  3. 500 2000
  4. 1000 4000
  5. 1100 3000
  6. 6000 2000
  7. 8000 1400
  8. 6000 1200
  9. 2000 1900

Output for Sample Input

  1. 4
  2. 4
  3. 5
  4. 9
  5. 7
  1.  
  1. 天啊,好可耐的老鼠,抱抱。
  1.  
  1. 为达到DP的无后续性,以其中一个为关键词排序,然后最长上升subque
  1. 从后向前不需要倒序输出。从前向后不要忘记倒序输出:
  1. 数组记录或者递归实现。
  1.  
  1.  
  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<iostream>
  4. #include<algorithm>
  5. using namespace std;
  6. int m,x,y;
  7. struct in{
  8. int w,s,pos,pre,num;
  9. }a[];
  10. int b[];
  11. bool cmp(in a,in b){
  12. return a.w<b.w;
  13. }
  14. void _solve()
  15. {
  16. for(int i=;i<=m;i++){
  17. for(int j=;j<i;j++){
  18. if(a[i].w>a[j].w&&a[i].s<a[j].s)
  19. if(a[i].num<a[j].num+){
  20. a[i].num=a[j].num+;
  21. a[i].pre=j;
  22. }
  23. }
  24. }
  25. int M=,L=;
  26. for(int i=m;i>=;i--)
  27. {
  28. if(a[i].num>M) {
  29. M=a[i].num;
  30. L=i;
  31. }
  32. }
  33. printf("%d\n",M);
  34. int t=;
  35. while(L>){//也可以试试调用递归来倒序输出
  36. b[++t]=a[L].pos;
  37. L=a[L].pre;
  38. }
  39. for(int i=t;i>=;i--) printf("%d\n",b[i]);
  40. return ;
  41. }
  42. int main()
  43. {
  44. while(~scanf("%d%d",&x,&y))
  45. {
  46. a[++m].w=x;
  47. a[m].s=y;
  48. a[m].pos=m;
  49. a[m].num=;
  50. }
  51. sort(a+,a+m+,cmp);
  52. _solve();
  53. return ;
  54. }
  1.  
  1.  
  1.  

zoj 1108 FatMouse's Speed 基础dp的更多相关文章

  1. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  2. FatMouse's Speed 基础DP

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. ZOJ 1108 FatMouse's Speed (HDU 1160) DP

    传送门: ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=108 HDU :http://acm.hdu.edu.cn/s ...

  4. [HDOJ1160]FatMouse's Speed(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...

  5. HDU 1160 FatMouse's Speed(DP)

    点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...

  6. HDU 1160 FatMouse's Speed LIS DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...

  7. hdu FatMouse's Speed 动态规划DP

    动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid ...

  8. HDU 1160 FatMouse's Speed (sort + dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...

  9. HDU FatMouse's Speed 基本DP

    题意:要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数.Special Judge 思路:先按体重由小到大排序,再找最长速度递减序列. 转移方程:mou[i].w> ...

随机推荐

  1. 利用Java调用OpenCV进行人脸识别

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt409 今天我准备学习如何用Java来进行人脸检测.人脸检测有助于在任何数字图 ...

  2. 学习Python Day1

    学习PythonDay1,主要是学习了循环,while循环,for循环:while循环加if.else以及elif,for循环嵌套for循环:break,终止循环,continue跳出循环:for i ...

  3. jsp---jstl配置

    关于eclipse中jstl标准标签库的配置问题 我的eclipse的版本是:Version: Neon.3 Release (4.6.3) 用的1.8.0_121的jre,Tomcat用的9.0, ...

  4. HTTP请求响应机制与响应状态码

    转载来源:http://blog.csdn.net/xyw591238/article/details/51907143 HTTP协议 Internate的基本协议是TCP/IP(传输控制协议和网际协 ...

  5. 1~N任意三个数最大的最小公倍数(Java版)

    最大最小公倍数 如题 话不多说,直接上代码 public class MaxCommonMultiple{ public static void main(String[] args) { Scann ...

  6. return 的使用

    (一):while中使用return //编译不通过,编译器不知道isTrue()方法是否会返回true,这样不能test()方法一定有返回值. public String test(){ while ...

  7. 201521123003《Java程序设计》第7周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 参考资料: XMind 2. 书面作业 Q1.ArrayList代码分析 1.1 解释ArrayList的contains源 ...

  8. 201521123010 《Java程序设计》第3周学习总结

    1. 本周学习总结 2. 书面作业 1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; p ...

  9. 20152112308 《Java程序设计》第3周学习总结

    本周学习总结 书面作业 1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; public ...

  10. 201521123010 《Java程序设计》第13周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 书面作业 1. 网络基础 1.1 比较ping www.baidu.com与ping cec.jmu ...