HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)
FatMouse's Speed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24573 Accepted Submission(s): 10896
Special Judge
Problem Description
Input
The
data for a particular mouse will consist of a pair of integers: the
first representing its size in grams and the second representing its
speed in centimeters per second. Both integers are between 1 and 10000.
The data in each test case will contain information for at most 1000
mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
Output
Your
program should output a sequence of lines of data; the first line
should contain a number n; the remaining n lines should each contain a
single positive integer (each one representing a mouse). If these n
integers are m[1], m[2],..., m[n] then it must be the case that
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[n]]
In order for the answer to be correct, n should be as large as possible.
All
inequalities are strict: weights must be strictly increasing, and
speeds must be strictly decreasing. There may be many correct outputs
for a given input, your program only needs to find one.
Sample Input
Sample Output
题目大意与分析
给出一堆鼠标的重量与速度,输出一个最长的序列,满足重量越来越大,速度越来越小。
先将鼠标根据重量从小到大排序,再求最大下降子序列就行了。
#include<bits/stdc++.h> using namespace std; typedef struct
{
int add;
int w;
int s;
}node;
node a[];
int dp[],anss,i,temp,c[],x,y,num,j,n;
bool cmp(node a,node b)
{
return a.w<b.w;
} int main()
{
while(cin>>x>>y)
{
num++;
a[num].add=num;
a[num].w=x;
a[num].s=y;
}
sort(a+,a++num,cmp);
for(i=;i<=num;i++)
{
dp[i]=;
for(j=;j<i;j++)
{
if(a[j].w<a[i].w&&a[j].s>a[i].s)
dp[i]=max(dp[j]+,dp[i]);
}
if(dp[i]>anss)
anss=dp[i];
}
cout<<anss<<endl;
temp=anss;
for(i=num;i>=;i--)
{
if(dp[i]==temp)
{
temp--;
c[temp]=a[i].add;
}
}
for(i=;i<anss;i++)
cout<<c[i]<<endl; }
HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)的更多相关文章
- HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形
题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...
- HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)
题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...
- HDU 1160 FatMouse's Speed (sort + dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
- HDU 1160 FatMouse's Speed(DP)
点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...
- HDU - 1160 (FatMouse's Speed )最长上升子序列
题意:一个元素有两个属性 w 和 sp 求在w严格递增的情况下 sp严格递减 用结构体 定义三个参数 w sp ix , ix是在输入时的顺序 因为我们要排序 之后把结构体数组 按从小到大排序 ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1160 FatMouse's Speed (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
随机推荐
- Ajax异步传值总结
Ajax异步传值 将数据从前台传向后台: 1:通过get方式,将参数在链接中,配合“?”进行传值. 实例: //前台传值方法 //触发该方法调用ajax function testAjax(yourD ...
- 运行时错误:“stack around the variable…was corrupted”
造冰箱的大熊猫@cnblogs 2018/11/1 引发问题的代码片段如下 WORD var; scanf ( "%d", &var ); 包含上述代码的程序,编译正常,运 ...
- AngularJS基础语法
1.ng-app 决定了angularjs的作用域范围,你可以如下使用: <html ng-app> … </html> 来让angularjs渲染整个页面,也可以使用 < ...
- 快速搭建 Serverless 人脸识别离线服务
简介 首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute):函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传.函数计算准 ...
- 12.Python数值类型(整形、浮点型和复数)及其用法
实际开发中,我们经常需要使用数字记录游戏中用户的得分.游戏中角色的生命值.伤害值等信息,Python 语言提供了数值类型用于保存这些数值. 需要注意的是,Python 中这些数值类型都是不可改变的,也 ...
- 第十三周Java课程学习总结
学习总结: 记事本界面: 监听适配器. 可以通过Window Adapter来实现监听. void windowActivated(WindowEvent e) 激活窗口时调用. void windo ...
- MessageWebSocket
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; usi ...
- MongoDB简单查询语句<平时使用语录,持续更新>
MongoDB查询语句 --查询近三个月的客户使用量 aggregate:使用聚合 match:过滤 group分组 -- mysql中select org_code as 近三个月使用商户 ...
- 【flask】flask项目配置 app.config
[理论] 在很多情况下,你需要设置程序的某些行为,这时你就需要使用配置变量.在Flask中,配置变量就是一些大写形式的Python变量, 你也可以称之为配置参数或配置键.使用统一的配置变量可以避免在程 ...
- 阶段3 3.SpringMVC·_01.SpringMVC概述及入门案例_04.入门程序之搭建开发环境
选择骨架构建 默认选中next-然后finish后就会去网上下载插件.会比较耗费时间. 添加一组键值对: archetypeCatalog internal 添加了这组坚持对,就可以解决Mavn项目创 ...