【HDOJ】1160 FatMouse's Speed
DP。
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define MAXNUM 1005
- typedef struct {
- int w, s;
- int index;
- } mouse_st;
- mouse_st mouses[MAXNUM];
- int dp[MAXNUM], next[MAXNUM];
- int comp(const void *a, const void *b) {
- mouse_st *p = (mouse_st *)a;
- mouse_st *q = (mouse_st *)b;
- if (p->w == q->w)
- return p->s - q->s;
- else
- return q->w - p->w;
- }
- int main() {
- int n=, m, beg;
- int i, j, max, index;
- while (scanf("%d %d", &mouses[n].w, &mouses[n].s) != EOF) {
- mouses[n].index = n;
- ++n;
- }
- memset(dp, , sizeof(dp));
- qsort(mouses, n, sizeof(mouse_st), comp);
- for (i=; i<n; ++i)
- next[i] = i;
- m = ;
- for (i=; i<n; ++i) {
- max = ;
- for (j=; j<i; ++j) {
- if (mouses[j].w>mouses[i].w && mouses[j].s<mouses[i].s) {
- if (max < dp[j]) {
- max = dp[j];
- index = mouses[j].index;
- }
- }
- }
- if (max)
- next[mouses[i].index] = index;
- dp[i] = max + ;
- if (m < dp[i]) {
- m = dp[i];
- beg = mouses[i].index;
- }
- }
- if (m == )
- printf("1\n1\n");
- else {
- printf("%d\n", m);
- while (next[beg] != beg) {
- printf("%d\n", beg+);
- beg = next[beg];
- }
- printf("%d\n", beg+);
- }
- return ;
- }
【HDOJ】1160 FatMouse's Speed的更多相关文章
- 【HDOJ】1009 FatMouse' Trade
这道题目是一道非常简单的贪心,但是我却修改了1h+.原因就是qsort的comp有bug.其实还是题目中的数据可以为0.除数为0真的要慎重啊.后来改为结构体,加一层循环选取最大值,果然ac啊.wa了几 ...
- 【HDOJ】1078 FatMouse and Cheese
这道题目是典型的DFS+记忆化搜索, DP思想.符合:含重叠子问题,无后效性等特点. #include <cstdio> #include <cstring> #include ...
- 【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed
https://vjudge.net/contest/68966#problem/J [Accepted] #include<iostream> #include<cstdio> ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1160 FatMouse's Speed (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
- Hdoj 1160.FatMouse's Speed 题解
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
随机推荐
- CSS样式表介绍
一. CSS中的样式选择 1)内样式(内联样式) style=””; 2)内嵌样式 <style type="text/css"></style> 3 ...
- 对进度条progressbar的调整
进度条的理解,感觉这个进度条不是那么简单,系统给我们定制了几个普通的,但是如果还需要有更加好的效果,需要自己去调试. <ProgressBar android:layout_width=&quo ...
- 几种工具反编译被编译好的DLL文件
我们平时在工作中经常会遇到一些已经被编译后的DLL,而且更加麻烦是没有源代码可以进行修改,只能针对这个DLL的文件进行修改才能得到我们想要的结果:本文将通过一个实例来演示如果完成一个简单的修改;我们将 ...
- linux mysql 安装(rpm)
linux上安装mysql, 就需要两个文件, xx.client.xx.rpm和 xx.server.xx.rpm 如 MySQL-client-community-5.1.72-1.rhel5.i ...
- ibatis调存储过程返回游标
http://blog.sina.com.cn/s/blog_6f3ca78f01010pmj.html iBatic调用与JAVA调用很类似,只是JAVA把参数的注册放到了类里面,而iBatis把参 ...
- websocket++简单使用例子
前言 html5支持使用websocket协议与服务器保持一个长连接,方便双方互相传输数据,而且服务器也能主动发送信息给客户端,而在这之前使用HTTP是很难做到的.下面介绍使用C++实现的websoc ...
- 《sort帮你排序》-linux命令五分钟系列之二十六
本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...
- 青瓷qici - H5小游戏 抽奖机 2 界面布局
背景图片 首先我们需要在当前场景下面创建UI的根节点,这个根节点决定了我们整个游戏的元素布局,以及适应多分辨率的缩放布局问题,所以我们其他的元素都要放在UIRoot下面. 考虑到我自己测试的时候在PC ...
- HTML5的全局属性
contentEditable:是否允许用户编辑元素中的内容.contentEditable有两个值,一个True 一个False. 例子: <ul contentEditable=" ...
- 2016年1月编程语言排行榜:Java荣获2015年度冠军
Java因于2015年人气增幅最大(+ 5.94%),故获得2015年的TIOBE指数的编程语言奖,同时成为15年年度冠军, Visual Basic.NET(+ 1.51%)和Python(+ 1. ...