HDU 1160 FatMouse's Speed LIS DP
http://acm.hdu.edu.cn/showproblem.php?pid=1160
同样是先按它的体重由小到大排,相同就按speed排就行。
这样做的好处是,能用O(n^2)枚举,因为前面的肯定不能和后面的搭配了。
然后就是LIS的题了,
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
struct node {
int weight, speed;
int id;
node(int a, int b, int c) : weight(a), speed(b), id(c) {}
node() {}
bool operator < (const struct node & rhs) const {
if (weight != rhs.weight) return weight < rhs.weight;
else return speed > rhs.speed;
}
}a[maxn];
struct DP {
int val;
struct node cur;
int pre;
}dp[maxn];
bool isok(struct node a, struct node b) {
if (a.weight < b.weight && a.speed > b.speed) return true;
else return false;
}
bool isbetter(struct node a, struct node b) {
if (a.weight != b.weight) return a.weight < b.weight;
else if (a.speed != b.speed) return a.speed > b.speed;
return false;
}
void show(int id) {
if (id == -inf) return;
show(dp[id].pre);
printf("%d\n", a[id].id);
}
void work() {
int total = ;
int c, d;
while (scanf("%d%d", &c, &d) != EOF) {
++total;
a[total] = node(c, d, total);
}
sort(a + , a + + total);
for (int i = ; i <= total; ++i) {
dp[i].val = ;
dp[i].pre = -inf;
dp[i].cur = a[i];
for (int j = ; j < i; ++j) {
if (isok(dp[j].cur, dp[i].cur)) { // i能接在j后面
if (dp[i].val < dp[j].val + ) {
dp[i].val = dp[j].val + ;
dp[i].pre = j;
} else if (dp[i].val == dp[j].val + ) {
if (isbetter(a[j], a[dp[i].pre])) { //j比它前一个好
dp[i].pre = j;
}
}
}
}
}
int ans = -inf;
int id;
for (int i = ; i <= total; ++i) {
if (ans < dp[i].val) {
ans = dp[i].val;
id = i;
}
}
printf("%d\n", ans);
show(id);
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}
HDU 1160 FatMouse's Speed LIS DP的更多相关文章
- HDU 1160 FatMouse's Speed (sort + dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
- HDU 1160 FatMouse's Speed(DP)
点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...
- HDU 1160 FatMouse's Speed ——(DP)
又是那个lis变形的题目. 但是不好定义严格的比较符号,因此只能n^2去做.值得注意的一个是要先排序,因为可能可以先选后面的再选前面的,先排序的话就能够避免这个问题.但是要注意,因为要输出路径,所以要 ...
- 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 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- 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(最长不下降子序列+输出路径)
题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...
随机推荐
- dd备份文件系统
1.实现dd的备份: 使用gzip压缩: dd if=/dev/hdb | gzip > /local/path/image.gz 说明:/dev/hdb 是硬盘整盘.对不同的硬盘,可能是 /d ...
- MySQL活动期间制定月份注册用户下单情况_20161029
在10.29到10.31号期间 10月新注册的用户订单金额满600元赠与优惠券 #3天内订单满600元且10月注册的用户订单明细 SELECT a.城市,a.用户ID,b.用户名称,DATE(b.注册 ...
- django orm 操作符
__gt 大于__gte 大于等于__lt 小于__lte 小于等于__in__exact 精确等于 like 'aaa'__iexact 精确等于 忽略大小写 ilike 'aaa'__contai ...
- UVa 714 Copying books 贪心+二分 最大值最小化
题目大意: 要抄N本书,编号为1,2,3...N, 每本书有1<=x<=10000000页, 把这些书分配给K个抄写员,要求分配给某个抄写员的那些书的编号必须是连续的.每个抄写员的速度是相 ...
- 深入理解和探究Java类加载机制
深入理解和探究Java类加载机制---- 1.java.lang.ClassLoader类介绍 java.lang.ClassLoader类的基本职责就是根据一个指定的类的名称,找到或者生成其对应的字 ...
- C#自定义控件 类似于Linechart
界面效果: 对外提供的属性设置 /// <summary> /// 背景色 /// </summary> public Color BackColor; /// <sum ...
- Entity Framework之领域驱动设计实践
http://www.cnblogs.com/daxnet/archive/2010/11/02/1867392.html
- JSP环境探针-当前电脑所有系统参数
1 <%@ page contentType="text/html;charset=gb2312" %> <%@ page import="java.u ...
- c# dll自动注册
在网上看到一个c# dll自动注册的文章,我测试了一下,可用. 下面是具体代码 [DllImport("Ry4SCom.dll")] public static extern in ...
- 转:isualvm远程监控Tomcat
一.Java VisualVM 概述 对于使用命令行远程监控jvm 太麻烦 . 在jdk1.6 中 Oracle 提供了一个新的可视化的. JVM 监控工具 Java VisualVM .jvisua ...