J - FatMouse's Speed

DP的题写得多了慢慢也有了思路,虽然也还只是很简单的DP

因为需要输出所有选择的老鼠,所以刚开始的时候想利用状态压缩来储存所选择的老鼠,后面才发现n太大1<<1000根本存不下来...

思路的话其实也不难,把体重排序之后,对速度求一个最长下降子序列即可。

对于每一次求最长有序子序列,只需要全部遍历一遍,遍历的时候,将该位置作为所选择序列的最后一个元素,DP[i]即为该序列的最大长度。

代码:

// Created by CAD on 2019/10/29.
#include <bits/stdc++.h>
using namespace std; struct state{
int pre=-1;
int cnt=1;
}dp[1005];
struct mouse{
int speed,weight;
int id;
bool operator<(mouse &m)
{
if(weight!=m.weight)
return weight<m.weight;
else return speed>m.speed;
}
}m[1005];
void print(int n)
{
if(n==-1) return ;
print(dp[n].pre);
cout<<m[n].id<<endl;
}
int main()
{
// FOPEN;
ios::sync_with_stdio(false);
cin.tie(0);
int n=0,ans=0;
while(cin >> m[n].weight >> m[n].speed)
{
m[n].id=n+1;
n++;
}
sort(m, m+n);
for(int i=0; i<n; i++)
{
for(int k=0; k<i; ++k)
{
if(m[k].weight<m[i].weight && m[k].speed>m[i].speed&&dp[k].cnt+1>dp[i].cnt)
dp[i].cnt=dp[k].cnt+1, dp[i].pre=k;
}
if(dp[ans].cnt<dp[i].cnt)
ans=i;
}
cout<<dp[ans].cnt<<endl;
print(ans);
return 0;
}

FatMouse's Speed的更多相关文章

  1. FatMouse's Speed——J

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

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

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

  3. HDU 1160 FatMouse's Speed (DP)

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

  4. FatMouse's Speed(HDU LIS)

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

  5. FatMouse's Speed 基础DP

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

  6. zoj 1108 FatMouse's Speed 基础dp

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

  7. J - FatMouse's Speed

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

  8. HDU 1160:FatMouse's Speed(LIS+记录路径)

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

  9. (最长上升子序列 并记录过程)FatMouse's Speed -- hdu -- 1160

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/Other ...

  10. zoj 1108 FatMouse's Speed 基础dp

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

随机推荐

  1. 利用ant-design封装react的地址输入组件

    在上一节利用element-ui封装地址输入的组件留下了个尾巴,说react搭配ant-design封装一下地址输入的组件的.本来应该早早就完成的,但是由于这中间发生了一些事情,导致了突发性的换了工作 ...

  2. 怎样设置Cookie

    因为 Cookie 是服务器保存在浏览器中的一小段信息, 因此这个设置应当是服务器发起的, 设置方法是在Response Header中添加: Set-Cookie字段, 值是多个键值对. 如下: / ...

  3. image的路径写法格式

    if (MapGrid.Visibility == Visibility.Visible) {      this.MapGrid.Visibility = Visibility.Collapsed; ...

  4. activity与service之间的通信方式

    Activity之间的通信 1.activity与activity的通信可以通过Intent来封装数据,startActivityForResult()来实现,当跳转的activity调用finish ...

  5. body测试onclick等鼠标事件无效果详解

    DOM事件机制包括五部分: DOM事件级别 DOM事件流 DOM事件模型 事件代理 Event对象常见的方法和属性 但是有时候发现给body标签里设置onclick属性,不起作用,代码如下: 不管单击 ...

  6. 在eclipse导入项目的步骤

    1. Import 2. Next 3. 确定  选中copy projects into workspace    Finish 这样项目就导入进来了. 4.导入jar包 Configure Bui ...

  7. nhandled rejection Error: EPERM: operation not permitted, open 'C:\Program Files\nodejs\node_cache npm ERR! cb() never called!

    安装全局包时报错,之前已经遇到过,结果第二次又忘记解决方法,果然还是要记下来,好记性不如烂笔头哇 $ npm i electron -gUnhandled rejection Error: EPERM ...

  8. C# TabControl 带删除

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostic ...

  9. vi和vim的使用

    本章内容: vi编辑器简介 vim基本使用 vim使用技巧 一.vim简介 vim是一个全屏幕纯文本编辑器,是vi编辑器的增强版. 二.vim的基本使用 1.vim的工作模式 命令模式:是主要使用快键 ...

  10. YOLO---YOLOv3 with OpenCV安装与使用

    Yolo v3+Opencv3.4.2安装记录 @wp20180930 目录 一.环境要求 (1)python版本的查看 (2)opencv版本的查看 二.文件下载 三.数据自测 四.问题与解决 (1 ...