#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
const int maxn=;
struct point
{
int w,s,per,id;
}p[maxn];
int cmp(point a,point b)
{
return a.s>b.s;
}
int dp[maxn];
int main()
{
int i,j,k,n,m;
n=;
memset(dp,,sizeof(dp));
while(scanf("%d%d",&p[n].w,&p[n].s)!=EOF)
{
p[n].id=n;
p[n].per=;
n++;
}
sort(p+,p+n,cmp);
int max;
dp[]=;//dp[i]记录以第i个元素结尾的最长递增的长度
for(i=;i<n;i++)
{
max=;
for(j=;j<i;j++)
{
if(p[j].w<p[i].w && p[j].s>p[i].s)
{
if(dp[j]>=max)
{
max=dp[j];
p[i].per=j;//记录i位置的前驱
}
}
dp[i]=max+;
}
}
max=-0x3f3f3f3f;
int end;
for(i=;i<n;i++)
{
if(max<=dp[i])
{
max=dp[i];
end=i;
}
}
printf("%d\n",max);
stack<int> ok;
while(end!=)
{
ok.push(end);
end=p[end].per;
}
while(!ok.empty())
{
printf("%d\n",p[ok.top()].id);
ok.pop();
}
return ;
} /*二分写法*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
struct X{
int s,w,sb;
};
bool cmp(X a,X b)
{
return (a.s>b.s)||(a.s==b.s&&a.w>b.w);//这里排序注意了,由于本题数据水的不能再水,a.w<b.w也过了,正解应该是a.w>b.w
}
X xx[];
int pre[];
int fnm[];
int shuchu[];
int main()
{
int i=,n=,w,s;
while(scanf("%d%d",&w,&s)!=EOF)
{
xx[n].w=w;
xx[n].s=s;
xx[n].sb=n++;
}
n--;
sort(xx+,xx+n+,cmp);/*
for(i=1;i<=n;i++)
printf("%d %d\n",xx[i].w,xx[i].s);*/
int lsb=,j,l,r;
fnm[]=;
pre[fnm[]]=-;
for(i=;i<=n;i++)
{
l=,r=lsb;
while (l<=r) //二分查找
{
int mid = (l+r)>>;
if (xx[fnm[mid]].w < xx[i].w)
l=mid+;
else
r=mid-;
}
j=l;
if(j>lsb)
lsb++;
fnm[j]=i;//存下标,相当于c[j]=a[i];
if(j!=)//fnm小标从0开始,所以要判断第一个
pre[i]=fnm[j-];//j-1的元素肯定是最长递增中的元素
else
pre[i]=-;
}
printf("%d\n",lsb+);
int xsb=fnm[lsb];
i=;
while(pre[xsb]!=-)
{
shuchu[i++]=xx[xsb].sb;
xsb=pre[xsb];
}
printf("%d\n",xx[xsb].sb);
for(i=lsb-;i>=;i--)
printf("%d\n",shuchu[i]);
return ;
}

HDU1160FatMouse's Speed的更多相关文章

  1. HDU-1160-FatMouse's Speed(线性DP,LIS)

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

  2. 动态规划:HDU1160-FatMouse's Speed(记录动态规划状态转移过程)

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

  3. HDU-1160-FatMouse's Speed(DP, 最长递增子序列)

    链接: https://vjudge.net/problem/HDU-1160 题意: FatMouse believes that the fatter a mouse is, the faster ...

  4. hdu FatMouse's Speed 动态规划DP

    动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid ...

  5. LYDSY模拟赛day2 Dash Speed

    /* 弃坑 */ #include<cstdio> #include<algorithm> using namespace std; ,M=N*; ],nxt[N<< ...

  6. FatMouse's Speed——J

    J. FatMouse's Speed FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  7. OpenVZ VPS加速方案–Final Speed

    body,td { font-family: 微软雅黑; font-size: 10pt }   OpenVZ VPS加速方案–Final Speed OpenVZ VPS加速方案–Final Spe ...

  8. UNITY3D单词学习 speed和velocity的区别

    在日常用语中,这两个词没有区别,可以通用. 而在物理学里,velocity 是一个矢量(vector quantity)表示起点与终点间直线距离的长度除以所用时间所得的量,并注明方向;而 speed ...

  9. HD1160FatMouse's Speed(最长单调递增子序列)

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

随机推荐

  1. ThreadUtil 多线程处理List,回调处理具体的任务

    每次想多线程处理一个大的结果集的时候 都需要写一大堆代码,自己写了个工具类 方便使用 package com.guige.fss.common.util; import com.guige.fss.c ...

  2. Oracle分页查询sql语句

    1. select * from ( select  t.*, rownum RN from TABLE_NAME  t ) where RN > 0 and RN <= 15 2. se ...

  3. 重装Delphi10.2的IDE必要设置

    重装Delphi10.2的IDE必要设置: 1,Tools->Options Editor Options->Display 右侧的 Right margin: 设为200 这个设置是为右 ...

  4. JS-高程3(更新中...)

    附录A 名词解析: const:声明常量,常量的值不能通过重新赋值来改变,并且在初始赋值后,不能重新声明.重新赋值了. 即:同一作用域中,常量名不能与其他变量或函数名重名.值也不能修改了. “常量是块 ...

  5. RabbitMQ的安装和使用Python连接RabbitMQ

    绪论 这里的环境使用的是Mac OS X系统,所有的配置和使用都是基于Mac OS X 和Python 2.7 以及对应的pika库的. RabbitMQ的安装和配置 安装部分 #brew insta ...

  6. 安装Hadoop系列 — 安装SSH免密码登录

    配置ssh免密码登录   1) 验证是否安装ssh:ssh -version显示如下的话则成功安装了OpenSSH_6.2p2 Ubuntu-6ubuntu0.1, OpenSSL 1.0.1e 11 ...

  7. Python - 3.6 学习第一天

    开始之前 基础示例 Python语法基础,python语法比较简单,采用缩紧方式. # print absolute value of a integer a = 100 if a >= 0: ...

  8. 问答项目---金币经验奖励规则及网站配置写入config文件

    具体步骤: 引入配置文件——>获取当前数组——>进行合并 public function edit(){ //引入 config.php配置文件 $file = APP_PATH.'Com ...

  9. html<input>输入框中各种正则表达式设置

    <%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding ...

  10. JavaScript三(对象思想)

    JavaScript并不是面向对象的程序设计语言,但它是基于对象的.JavaScript中的每个函数都可用于创建对象,返回的对象既是该对象的实例,也是object的实例 . 一.对象与关联数组 Jav ...