【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]二分得到 ...
随机推荐
- Git 常用配置和使用
Git:是一个分布式的源代码管理工具,Linux内核的代码就是用Git管理的所以它很强,也很快, 和 Vss/SVN比起来 本地Git初始化配置及其使用: 1. 初始化本地Git库:打开Git Bas ...
- c++ 学习之const专题之const成员函数
一些成员函数改变对象,一些成员函数不改变对象. 例如: int Point::GetY() { return yVal; } 这个函数被调用时,不改变Point对象,而下面的函数改变Point对象: ...
- ns2出现Client: Handoff Attempt的情况解决
找到mac/mac-802_11.cc,这是系统本身一个bug,对于adhoc网络无需进行切换尝试. > if (*rcount == 3 && handoff == 0) {& ...
- Javase中多态polymorphic的简单介绍
-------------多态----------------- (1)面向对象三大核心思想: 1.封装 2.继承 3.多态 (2)多态定义:父类的引用指向子类的对象. (3)引用指的是父 ...
- mysql相关重要问题解决
root密码修改 MySQL 的管理员密码: sudo mysqladmin -u root password newpassword: mysql无法安装:删除/etc/mysql, /var/ ...
- Telerik柱状图(1)
此随笔主要是介绍一下Telerik的柱状图控件中的一种.效果图为: 此图展示了五个人每个季度的绩效成绩,用图形方式展示数据可以让用户更直观的去看数据,分析数据,不多说了,在这个分享一下我录得视频讲解, ...
- NPOI_2.1.3-Excel中设置小数、百分比、货币、日期、科学计数法和金额大写
在操作Excel时候一些特殊值的转换是在所难免的,下面就给出转换方法大同小异,代码如下: HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); ISheet ...
- IE 动态绑定click事件
//必须先清除原有的事件 $(dom).attr("onclick", ""); //再重新绑定新的事件 $(dom).bind("click&quo ...
- wamp配置
# #localhost # <VirtualHost *:> DocumentRoot "D:/software/wamp/www" ServerName local ...
- 安装mysql-python需要碰到错误:Unable to find vcvarsall.bat 的解决方法
1.发现从https://pypi.python.org/pypi/MySQL-python/1.2.5#downloads 下载下来的python版本是2.7