题目大意:给你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的更多相关文章

  1. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. HDU 1160 FatMouse's Speed (DP)

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  3. HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化

    HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...

  4. HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. hdu 1160 FatMouse's Speed 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题目意思:给出一堆老鼠,假设有 n 只(输入n条信息后Ctrl+Z).每只老鼠有对应的weigh ...

  6. HDU 1160 FatMouse's Speed LIS DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...

  7. HDU 1160 FatMouse's Speed (sort + dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...

  8. hdu 1160 FatMouse's Speed (最长上升子序列+打印路径)

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  9. HDU - 1160 FatMouse's Speed 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...

随机推荐

  1. Intent之间无法传递大数据的替代方法

    /** * TODO: Activity之间传递list,对象等工具类 * * @author * @date 2014-9-12 下午5:35:38 * @version 0.1.0 */ publ ...

  2. 使用Java管理千台规模Linux服务器_入门

    http://www.oschina.net/code/snippet_222919_11734 代码分享 当前位置: 代码分享 » Java  » 网络编程 搜 索   [饶过] 使用Java管理千 ...

  3. Best Grass

    Description Bessie is planning her day of munching tender spring grass and is gazing out upon the pa ...

  4. UISegmentedControl 踩坑

    @interface JLMyContactsViewController () @property (nonatomic, strong)   UIImageView *navImageView; ...

  5. JAVA字符串编码转换常用类

    无论是对程序的本地化还是国际化,都会涉及到字符编码的转换的问题.尤其在web应用中常常需要处理中文字符,这时就需要进行字符串的编码转换,将字符串编码转换为GBK或者GB2312.一.关键技术点:    ...

  6. HDU 1815 Building roads

    二分答案 + 2-SAT验证 POJ 稳过,HDU C++ 超时,G++ 550ms左右AC #include<cstdio> #include<cstring> #inclu ...

  7. C# 开发技巧]如何防止程序多次运行 线程 进程

    程序员必有一些好习惯,我的就是看到好文章就收下 文章来源   http://www.cnblogs.com/zhili/p/OnlyInstance.html 转载请注明出处 最近发现很多人在论坛中问 ...

  8. MIME (Multipurpose Internet Mail Extensions) 是描述消息内容类型的因特网标准

    http://www.alixixi.com/program/a/2010080364045.shtml MIME 消息能包含文本.图像.音频.视频以及其他应用程序专用的数据. 官方的 MIME 信息 ...

  9. rm link

    # this works rm foo # versus rm foo/

  10. selenium firefox

    https://github.com/SeleniumHQ/selenium/blob/master/java/CHANGELOG https://github.com/mozilla/geckodr ...