博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1160 FatMouse's Speed (最长递减子序列)
阅读量:6346 次
发布时间:2019-06-22

本文共 2364 字,大约阅读时间需要 7 分钟。

FatMouse's Speed

FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.

Input
Input contains data for a bunch of mice, one mouse per line, terminated by end of file.

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
6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900
Sample Output
4
4
5
9
7

题意

我们是要在原来的老鼠序列中,找到一个最长的子序列,使得这个子序列中老鼠的体重在严格增加,速度却在严格降低。

首先输出满足条件的最长的子序列的长度。
其次,输出一个最长子序列的方案,要求输出每个老鼠在输入时候的编号,每个编号占一行,任意一种正确的方法都会被判正确。

题解

模板题,输出编号可以记录一下前驱,最后递归输出就行。

#include
#include
#include
#include
using namespace std;const int INF=0x3f3f3f3f;const int maxn=1005;typedef long long LL;int dp[maxn],path[maxn];struct mouse{ int id,w,s; bool operator <(const mouse& x)const { if(w==x.w) return s>x.s; return w
m[i].s&&dp[i]<=dp[j]) { dp[i]=dp[j]+1; path[m[i].id]=m[j].id; } } if(dp[i]>ans) { ans=dp[i]; ans_id=m[i].id; } } printf("%d\n",ans); print(ans_id); return 0;}

转载于:https://www.cnblogs.com/orion7/p/8454425.html

你可能感兴趣的文章
Java统计文件夹中文件总行数
查看>>
python之基本数据类型及深浅拷贝
查看>>
将bootstrap弹出框的点击弹出改为鼠标移入弹出
查看>>
SKF密码设备研究
查看>>
数据对象映射模式(通过工厂模式和注册树模式)v2
查看>>
4939 欧拉函数[一中数论随堂练]
查看>>
MySQL笔记(一)
查看>>
spring boot 包jar运行
查看>>
18年秋季学习总结
查看>>
Effective前端1:能使用html/css解决的问题就不要使用JS
查看>>
网络攻防 实验一
查看>>
由莫名其妙的错误开始---浅谈jquery的dom节点创建
查看>>
磨刀-CodeWarrior11生成的Makefile解析
查看>>
String StringBuffer StringBuilder对比
查看>>
bootstrap随笔点击增加
查看>>
oracle 中proc和oci操作对缓存不同处理
查看>>
[LeetCode] Spiral Matrix 解题报告
查看>>
60906磁悬浮动力系统应用研究与模型搭建
查看>>
指纹获取 Fingerprint2
查看>>
面试题目3:智能指针
查看>>