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 ...
随机推荐
- Jexus是一款Linux平台上的高性能WEB服务器和负载均衡网关
什么是Jexus Jexus是一款Linux平台上的高性能WEB服务器和负载均衡网关,以支持ASP.NET.ASP.NET CORE.PHP为特色,同时具备反向代理.入侵检测等重要功能.可以这样说,J ...
- POJ1195Mobile phones (从二维树状数组到cdq分治)
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...
- ACM学习历程——HDU5015 233 Matrix(矩阵快速幂)(2014陕西网赛)
Description In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 2 ...
- SQL 优化总结(二) 索引
索引 1.索引的建立 缺省情况下建立的索引是非群集索引,但有时它并不是最佳的:合理的索引设计要建立在对各种查询的分析和预测上. 一般来说: (1) 有大量重复值.且经常有范围查询(between, ...
- jquery/原生js/css3 实现瀑布流以及下拉底部加载
思路: style: <style type="text/css"> body,html{ margin:; padding:; } #container{ posit ...
- Ajax的属性
1.属性列表 url: (默认: 当前页地址) 发送请求的地址. type: (默认: "GET") 请求方式 ("POST" 或 "GET ...
- Tomcat访问程序外的上传文件
自己在编写程序时,把图片上传到程序根目录下,但是页面使用<img> 没有显示.但是,当我刷新项目下文件夹后,页面刷新可以显示. 我通过网上查询,当在Tomcat下的server.xml配置 ...
- USB相关资料
http://www.usb.org/developers/defined_class/#BaseClass00h http://blog.csdn.net/lizzywu/article/detai ...
- HDU 1512 Monkey King (左偏树+并查集)
题意:在一个森林里住着N(N<=10000)只猴子.在一开始,他们是互不认识的.但是随着时间的推移,猴子们少不了争斗,但那只会发生在互不认识 (认识具有传递性)的两只猴子之间.争斗时,两只猴子都 ...
- day02-HTML(2)
一.新知识 1. !+tab html5的标签结构 2. Charset 编码 Ascll Ansi Unicode Gbk Gb2312 Big5 Utf-8 通用字符集 3.关 ...