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 ...
随机推荐
- 【leetcode】1249. Minimum Remove to Make Valid Parentheses
题目如下: Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the min ...
- EasyUI ComboBox ajax
ajax请求数据 $.post("get_select", { "type1" : "mytype" }, function(data) { ...
- python from…import* 语句
把一个模块的所有内容全都导入到当前的命名空间也是可行的,只需使用如下声明: from modname import * 这提供了一个简单的方法来导入一个模块中的所有项目.然而这种声明不该被过多地使用. ...
- USACO2018DEC GOLD
好简单啊.. T1裸分层图最短路. T2裸容斥. T3更水的DP. 代码 T1 #include <bits/stdc++.h> #define rin(i,a,b) for(regist ...
- Mongo Cursor
简介 在使用 Java 对数据库进行连接时,都会获取到一个 cursor ,cursor 实际指到的是我们查询数据库的query,而并不是 query 查询到的数据集. 此次在使用 mongo 的 c ...
- python第一个程序:计算体脂率
主要是为了提醒自己要——保重 height = input('请输入身高(m):') weight = input('请输入体重(KG):') age = input('请输入年龄:') sex = ...
- shiro 注解不生效
springboot集成shiro时,使用@RequiresRoles注解不生效. shiro @RequiresRoles底层使用springaop技术: 1.@RequiresRoles修饰ser ...
- 一起学vue指令之v-html
一起学vue指令之v-html 一起学 vue指令 v-html 指令可看作标签属性 某些情况下,我们点击百度搜索下一页,服务器应该就返回下一页的数据页面,包含其他资源链接等. 返回的数据的本质是一 ...
- java 方法的重载重写
面向对象有三大特性:封装,继承,多态 多态则需要满足三大条件1要有继承2要有重写3父类引用子类对象 很多人对方法的重载重写有很大疑问,下面我来介绍一下方法的重载重写 方法重载就是方法名称重复,加载参数 ...
- C++类继承方式及实践
直接上图: 以及: 实践如下: #include <iostream> using namespace std; class Father{ private: int father1; i ...