题目大意:读入一些数(每行读入$w[i],s[i]$为一组数),要求找到一个最长的序列,使得符合$w[m[1]] < w[m[2]] < ... < w[m[n]]$且$s[m[1]] > s[m[2]] > ... > s[m[n]]$,并输出每组数在读入时的顺序具体见原题目

思路:先根据w从小到大排序,再求最长下降子序列,DP时保存路径,最后递归输出路径。

C++ Code:

#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
int n=1;
struct sz{
int w,s,num;
bool operator <(const sz& rhs)const{
if(w!=rhs.w)return w<rhs.w;
return s>rhs.s;
}
}a[1020];
int d[1020],p[1020];
void dg(int n){
if(n==0)return;
dg(d[n]);
printf("%d\n",a[n].num);
}
int main(){
while(scanf("%d%d",&a[n].w,&a[n].s)!=EOF)a[n].num=n,n++;
n--;
sort(a+1,a+n+1);
memset(d,0,sizeof(d));//d[i]表示i的前一个数
memset(p,0,sizeof(p));//p[i]表示以s[i]结尾的最长下降子序列的长度
for(int i=1;i<=n;i++)p[i]=1;
for(int i=2;i<=n;i++){
for(int j=1;j<i;j++)
if(a[i].w>a[j].w&&a[i].s<a[j].s){//a[i].w>a[j].w不能去掉,因为可能出现两个w相等的情况
if(p[i]<p[j]+1){
p[i]=p[j]+1;
d[i]=j;
}
}
}
int t,max=0;
for(int i=1;i<=n;i++)
if(max<p[i]){
t=i;
max=p[i];
}
printf("%d\n",max);
dg(t);
return 0;
}

[HDU1160]FatMouse's Speed的更多相关文章

  1. HDU1160 FatMouse's Speed —— DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS ...

  2. HDU1160:FatMouse's Speed(最长上升子序列,不错的题)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1160 学的东西还是不深入啊,明明会最长上升子序列,可是还是没有A出这题,反而做的一点思路没有,题意就不多说 ...

  3. FatMouse's Speed——J

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

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

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

  5. HDU 1160 FatMouse's Speed (DP)

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

  6. FatMouse's Speed(HDU LIS)

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

  7. FatMouse's Speed 基础DP

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

  8. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  9. J - FatMouse's Speed

    p的思路不一定要到最后去找到ans:也可以设置成在中间找到ans:比如J - FatMouse's Speed 这个题,如果要是让dp[n]成为最终答案的话,即到了i,最差的情况也是dp[i-1],就 ...

随机推荐

  1. 使用shell脚本定时备份web网站代码

    #!/bin/bash ############### common file ################ #备份文件存放目录 WEBBACK_DIR="/data/backup/ba ...

  2. MySQL数据库中字段类型为tinyint,读取出来为true/false的问题

    由于MySQL中没有boolean类型,所以会用到tinyint类型来表示. 数据库一个表中有一个tinyint类型的字段,值为0或者1,如果取出来的话,0会变成false,1会变成true.

  3. Unknown tag (s:property).

    Unknown tag (s:property). 在jsp文件中加入此句话:<%@ taglib uri="/struts-tags" prefix="s&quo ...

  4. 说说sys_context函数

    select SYS_CONTEXT('USERENV', 'TERMINAL') terminal,        SYS_CONTEXT('USERENV', 'LANGUAGE') langua ...

  5. 百度url 参数详解全

    百度url解析Joe.Smith整理大全 百度url解析Joe.Smith整理大全...1 本文链接:http://blog.csdn.net/qq_26816591/article/details/ ...

  6. Hadoop(2)_机器信息分布表

    1.分布式环境搭建 采用4台安装Linux环境的机器来构建一个小规模的分布式集群. 图1 集群的架构 其中有一台机器是Master节点,即名称节点,另外三台是Slaver节点,即数据节点.这四台机器彼 ...

  7. MySQL 5.7.10最新版本号源码安装具体过程

    ,重置密码 利用mysqladmin重置密码 [root@wgq_idc_mon_1_12 mysql5710]#./bin/mysqladmin -h localhost -uroot passwo ...

  8. Windows 8.1内置微软五笔输入法

    微软五笔输入法採用86版编码,不是Windows 8.1系统的中文语言的缺省输入法,你在使用它之前须要把它加入到系统输入法中. 在控制面板双击"",然后加入微软五笔输入法. wat ...

  9. Manarcher 求 字符串 的最长回文子串 【记录】

    声明:这里仅仅写出了实现过程.想学习Manacher的能够看下这里给出的实现过程,算法涉及的一些原理推荐个博客. 给个链接 感觉讲的非常细 引子:给定一个字符串s,让你求出最长的回文子串的长度. 算法 ...

  10. v-cli环境的安装

    第一步:node   npm是node的包管理器  yarn 第二步:npm install -g vue-cli或者淘宝镜像                  如果安装失败:在node.js com ...