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 ...
随机推荐
- Hibernate 缓存机制详细分析
在本篇随笔里将会分析一下hibernate的缓存机制,包括一级缓存(session级别).二级缓存(sessionFactory级别)以及查询缓存,当然还要讨论下我们的N+1的问题. 随笔虽长,但我相 ...
- Jquery实现div左右重复来回走动
<!DOCTYPE HTML><html><head> <meta charset=utf-8 /> <title>UFO来了</ti ...
- BZOJ 1212: [HNOI2004]L语言 trie
长度小于 10 是关键信息~ #include <cstdio> #include <cstring> #include <algorithm> #define N ...
- K8S容器探针
容器探针 探针是由 kubelet对容器执行的定期诊断.要执行诊断, kubelet 调用由容器实现的 Handler .有三种类型的处理程序: ExecAction :在容器内执行指定命令 ...
- JS框架_(JQuery.js)绚丽的3D星空动画
百度云盘: 传送门 密码:8ft8 绚丽的3D星空动画效果(纯CSS) (3D星空动画可以用作网页背景,Gary为文本文字) <!doctype html> <html lang=& ...
- java实现数据库之间批量插入数据
package comnf147Package; import java.sql.*; public class DateMigrationLagou { //连接SQLite private Con ...
- 通过JVM日志来进行安全点分析
许多事件都可能会导致JVM暂停所有的应用线程.这类暂停又被称为”stop-the-world”(STW)暂停.触发STW暂停最常见的原因就是垃圾回收了(github中的一个例子),但不同的JIT活动( ...
- Error:Connection activation failed: No suitable device found for this connection
原文链接: https://blog.csdn.net/baiboya/article/details/80452822 ens33这个网卡一直无法激活,在网上找了半天,找到这个博主的文章,才解决,虽 ...
- JDBC连接数据库遇到的“驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。
要从旧算法列表中删除3DES: 在JDK 8及更早版本中,编辑该 /lib/security/java.security文件并3DES_EDE_CBC从jdk.tls.legacyAlgorithms ...
- js关闭当前页面(窗口)的几种方式
1. 不带任何提示关闭窗口的js代码 代码如下: <a href="javascript:window.opener=null;window.open('','_self');win ...