DP。

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. #define MAXNUM 1005
  6.  
  7. typedef struct {
  8. int w, s;
  9. int index;
  10. } mouse_st;
  11.  
  12. mouse_st mouses[MAXNUM];
  13. int dp[MAXNUM], next[MAXNUM];
  14.  
  15. int comp(const void *a, const void *b) {
  16. mouse_st *p = (mouse_st *)a;
  17. mouse_st *q = (mouse_st *)b;
  18. if (p->w == q->w)
  19. return p->s - q->s;
  20. else
  21. return q->w - p->w;
  22. }
  23.  
  24. int main() {
  25. int n=, m, beg;
  26. int i, j, max, index;
  27.  
  28. while (scanf("%d %d", &mouses[n].w, &mouses[n].s) != EOF) {
  29. mouses[n].index = n;
  30. ++n;
  31. }
  32.  
  33. memset(dp, , sizeof(dp));
  34. qsort(mouses, n, sizeof(mouse_st), comp);
  35. for (i=; i<n; ++i)
  36. next[i] = i;
  37. m = ;
  38.  
  39. for (i=; i<n; ++i) {
  40. max = ;
  41. for (j=; j<i; ++j) {
  42. if (mouses[j].w>mouses[i].w && mouses[j].s<mouses[i].s) {
  43. if (max < dp[j]) {
  44. max = dp[j];
  45. index = mouses[j].index;
  46. }
  47. }
  48. }
  49. if (max)
  50. next[mouses[i].index] = index;
  51. dp[i] = max + ;
  52. if (m < dp[i]) {
  53. m = dp[i];
  54. beg = mouses[i].index;
  55. }
  56. }
  57. if (m == )
  58. printf("1\n1\n");
  59. else {
  60. printf("%d\n", m);
  61. while (next[beg] != beg) {
  62. printf("%d\n", beg+);
  63. beg = next[beg];
  64. }
  65. printf("%d\n", beg+);
  66. }
  67.  
  68. return ;
  69. }

【HDOJ】1160 FatMouse's Speed的更多相关文章

  1. 【HDOJ】1009 FatMouse' Trade

    这道题目是一道非常简单的贪心,但是我却修改了1h+.原因就是qsort的comp有bug.其实还是题目中的数据可以为0.除数为0真的要慎重啊.后来改为结构体,加一层循环选取最大值,果然ac啊.wa了几 ...

  2. 【HDOJ】1078 FatMouse and Cheese

    这道题目是典型的DFS+记忆化搜索, DP思想.符合:含重叠子问题,无后效性等特点. #include <cstdio> #include <cstring> #include ...

  3. 【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed

    https://vjudge.net/contest/68966#problem/J [Accepted] #include<iostream> #include<cstdio> ...

  4. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

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

  5. HDU 1160 FatMouse's Speed (DP)

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  6. HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)

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

  7. HDU - 1160 FatMouse's Speed 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...

  8. Hdoj 1160.FatMouse's Speed 题解

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  9. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

随机推荐

  1. CSS样式表介绍

    一.    CSS中的样式选择 1)内样式(内联样式) style=””; 2)内嵌样式 <style type="text/css"></style> 3 ...

  2. 对进度条progressbar的调整

    进度条的理解,感觉这个进度条不是那么简单,系统给我们定制了几个普通的,但是如果还需要有更加好的效果,需要自己去调试. <ProgressBar android:layout_width=&quo ...

  3. 几种工具反编译被编译好的DLL文件

    我们平时在工作中经常会遇到一些已经被编译后的DLL,而且更加麻烦是没有源代码可以进行修改,只能针对这个DLL的文件进行修改才能得到我们想要的结果:本文将通过一个实例来演示如果完成一个简单的修改;我们将 ...

  4. linux mysql 安装(rpm)

    linux上安装mysql, 就需要两个文件, xx.client.xx.rpm和 xx.server.xx.rpm 如 MySQL-client-community-5.1.72-1.rhel5.i ...

  5. ibatis调存储过程返回游标

    http://blog.sina.com.cn/s/blog_6f3ca78f01010pmj.html iBatic调用与JAVA调用很类似,只是JAVA把参数的注册放到了类里面,而iBatis把参 ...

  6. websocket++简单使用例子

    前言 html5支持使用websocket协议与服务器保持一个长连接,方便双方互相传输数据,而且服务器也能主动发送信息给客户端,而在这之前使用HTTP是很难做到的.下面介绍使用C++实现的websoc ...

  7. 《sort帮你排序》-linux命令五分钟系列之二十六

    本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...

  8. 青瓷qici - H5小游戏 抽奖机 2 界面布局

    背景图片 首先我们需要在当前场景下面创建UI的根节点,这个根节点决定了我们整个游戏的元素布局,以及适应多分辨率的缩放布局问题,所以我们其他的元素都要放在UIRoot下面. 考虑到我自己测试的时候在PC ...

  9. HTML5的全局属性

    contentEditable:是否允许用户编辑元素中的内容.contentEditable有两个值,一个True 一个False. 例子: <ul contentEditable=" ...

  10. 2016年1月编程语言排行榜:Java荣获2015年度冠军

    Java因于2015年人气增幅最大(+ 5.94%),故获得2015年的TIOBE指数的编程语言奖,同时成为15年年度冠军, Visual Basic.NET(+ 1.51%)和Python(+ 1. ...