ZOJ 1108 & HDU 1160 - FatMouse's Speed
题目大意:给你n只老鼠的体重w和速度s,让你找出最长的子序列使得w[i] < w[j] 且 s[i] > s[j] (i < j)。求最长序列的长度并输出该序列。
LIS(Longest Increasing Subsequence)问题,先对老鼠进行排序,以w为第一关键字从小到大排序,再以s为第二关键字从大到小排序,然后就是LIS问题的处理了。LIS(i)表示以a[i]结尾的最长增长序列的长度。
#include <cstdio>
#include <algorithm>
using namespace std; struct Mouse
{
int id, w, s;
bool operator < (const Mouse &m) const
{
if (w != m.w) return w < m.w;
return s > m.s;
}
} mouse[];
int lis[], pre[]; void print_lis(int p)
{
if (pre[p] != -) print_lis(pre[p]);
printf("%d\n", mouse[p].id);
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int n = , a, b;
while (scanf("%d%d", &a, &b) != EOF)
{
mouse[n].w = a;
mouse[n].s = b;
mouse[n].id = n + ;
n++;
}
sort(mouse, mouse+n);
lis[] = ;
int p = ;
for (int i = ; i < n; i++)
pre[i] = -;
for (int i = ; i < n; i++)
{
lis[i] = ;
for (int j = ; j < i; j++)
if (mouse[i].w > mouse[j].w && mouse[i].s < mouse[j].s)
{
if (lis[j]+ > lis[i])
{
lis[i] = lis[j] + ;
pre[i] = j;
}
}
if (lis[i] > lis[p]) p = i;
}
printf("%d\n", lis[p]);
print_lis(p);
return ;
}
ZOJ 1108 & HDU 1160 - FatMouse's Speed的更多相关文章
- 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 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题目意思:给出一堆老鼠,假设有 n 只(输入n条信息后Ctrl+Z).每只老鼠有对应的weigh ...
- HDU 1160 FatMouse's Speed LIS DP
http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...
- HDU 1160 FatMouse's Speed (sort + dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
- hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
随机推荐
- Using Sphinx to index CNS database
1, look at the sphinx.person.address.conf to see how to configure the conf file2, index the database ...
- JS跨域代码
//部分JS代码 $.ajax({ async: false, url: "http://www.xxxx.com/api/", type: "GET",//不 ...
- OSPF的基本配置及DR /BDR选举的实验
OSPF的基本配置及DR /BDR选举的实验 实验拓扑: 实验目的:掌握OSPF的基本配置 掌握手工指定RID 掌握如何修改OSPF的接口优先级 观察DR BDR选举的过程 实验要求:R3当选为DR ...
- 使用Word API打开Word文档 ASP.NET编程中常用到的27个函数集
使用Word API(非Openxml)打开Word文档简单示例(必须安装Word) 首先需要引入参照Microsoft.Office.Interop.Word 代码示例如下: public void ...
- 判断android文件是否加壳
判断android文件是否加壳 查看文件是否有多个进程 反编译文件class.dex,看文件结构 查看文件特征,libsecexe libsecmain等 反编译so文件,看函数是否加密
- Bootstrap 容器(Container)及网格说明-(二)
1.容器(Container) 2.网格 来自为知笔记(Wiz)
- HDU - 2680 最短路 spfa 模板
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2680 题目大意,就是一个人可以从多个起点开始出发,看到终点的最短路是多少..只有可以运用和hdu2066 ...
- Learning Ionic中文版本
最近没有干劲,空闲时间也足,然后找了个比较容易集中精神的事情在做: 翻译<learning ionic> ionic是一个整合angularjs和cordova混合应用开发框架. 它可以通 ...
- Nginx配置文件常用部分详解
原文 #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes ; #全局错误日志定义类型,[ debug ...
- FCKeditor文字编辑器
FCKeditor文字编辑器的js调用1.需要fckeditor包 下载地址 http://dl.pconline.com.cn/html_2/1/776/id=48351&pn=0.html ...