链接:

https://vjudge.net/problem/HDU-1160

题意:

FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.

思路:

对s排序, 然后最长递增子序列,nlogn总有bug还是n2好用

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <sstream>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const LL MOD = 20090717;
const int MAXN = 1e3+10; struct Node
{
int w, s;
int id;
bool operator < (const Node& that) const
{
return this->s > that.s;
}
}node[MAXN];
int Dp[MAXN], Pre[MAXN];
int n; void Print(int p)
{
if (p == -1)
return;
Print(Pre[p]);
printf("%d\n", node[p].id);
} int main()
{
int l, r;
while (~scanf("%d%d", &l, &r))
{
node[++n].w = l;
node[n].s = r;
node[n].id = n;
}
sort(node+1, node+1+n);
memset(Pre, -1, sizeof(Pre));
memset(Dp, 0, sizeof(Dp));
for (int i = 1;i <= n;i++)
{
Dp[i] = 1;
for (int j = 1;j < i;j++)
{
if (node[i].w > node[j].w && node[i].s < node[j].s)
{
if (Dp[j]+1 > Dp[i])
{
Dp[i] = Dp[j]+1;
Pre[i] = j;
}
}
}
}
int maxval = 1, maxpos = 1;
for (int i = 1;i <= n;i++)
{
if (maxval < Dp[i])
{
maxval = Dp[i];
maxpos = i;
}
}
printf("%d\n", maxval);
Print(maxpos); return 0;
}

最新文章

  1. sublime 函数跳转插件 — ctags 安装和使用
  2. c8051f320学习,单片机不外乎时钟、IO、串口、USB等外设用法
  3. 关于centos的yum代理设置
  4. 【经典】C++&amp;RPG对战游戏
  5. Linux的常用基本命令
  6. Asp.net MVC4 网站发布
  7. Hibernate注解:一对一主键关联
  8. Spring JTA应用JOTM &amp; Atomikos II JOTM
  9. sgu 185 最短路建网络流
  10. 数据库事务的ACID和BASE
  11. [BZOJ 2004] [Hnoi2010] Bus 公交线路 【状压DP + 矩阵乘法】
  12. 数据结构学习:KMP模式匹配算法
  13. 8.C++-类的关键字
  14. Swift中 删除Array的元素对象
  15. truecrype加密卷的使用
  16. poj1990两个树状数组
  17. Javascript中的垃圾回收机制
  18. Linux基础命令---sum,cksum
  19. Unity 3D游戏-见缝插针源码
  20. JavaScript实现本地图片上传预览功能(兼容IE、chrome、FF)

热门文章

  1. [转帖]CentOS 8 正式发布
  2. sql复合索引使用和注意事项
  3. Word 查找替换高级玩法系列之 -- 制表符对齐人工目录
  4. MongoDB 范围查询
  5. Git 版本恢复命令reset
  6. MarkdownPad2安装与破解-转载
  7. C# Combox控件绑定自定义数据
  8. SourceTree撤销commit
  9. Hibernate-validate工具类,手动调用校验返回结果
  10. Missing Push Notification Entitlement解决方法