题目大意:读入一些数(每行读入$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. SpringBoot 国际化

    一.配置文件 二.application.properties 文件( 让国际化的文件被 SpringBoot 识别 ) spring.messages.basename=i18n.login 三.h ...

  2. mybatis入门截图四(订单商品数据模型-懒加载-缓存)

    <!-- 延迟加载的resultMap --> <resultMap type="cn.itcast.mybatis.po.Orders" id="Or ...

  3. Cache index coloring for virtual-address dynamic allocators

    A method for managing a memory, including obtaining a number of indices and a cache line size of a c ...

  4. HDU-1042-N!(Java大法好 &amp;&amp; HDU大数水题)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Subm ...

  5. poj 2396 Budget 边容量有上下界的最大流

    题意: 给一个矩阵的每行和及每列和,在给一些行列或点的限制条件.求一个满足的矩阵. 分析: 转化为有上下界的网络流,注意等于也是一种上下界关系,然后用dinic算法. 代码: //poj 2396 / ...

  6. WebRTC学习与DEMO资源一览

    一. WebRTC学习 1.1   WebRTC现状 本人最早接触WebRTC是在2011年底,那时Google已经在Android源码中加入了webrtc源码,放在/external/webrtc/ ...

  7. WEBSERVICE之JDK开发webservice

    转自:https://www.cnblogs.com/w-essay/p/7357262.html 一.开发工具与环境 1. jdk1.6版本以上(jdk1.6.0_21及以上版本) 2 .eclip ...

  8. 关于udebug的使用

    关于udebug的使用 特别强调: 转载于此 当你做国外OJ的题目时,总是不知道有什么问题,用题解打对拍都发现不出来,看到某道可恶美好的英文题目WA掉时,又不能下载样例时,会觉得很无奈吧.我们可以使用 ...

  9. Oracle 新手语法记录

    一.用户 1. 创建用户 语法:create user 用户名 identified by 口令; create user test identified by test; 2. 修改用户 语法:al ...

  10. python小项目之头像右上角加数字

    pillow介绍 一.Image类的属性:1.Format   2.Mode   3.Size    4.Palette    5.Info 二.类的函数:1.New   2.Open   3.Ble ...