FatMouse's Speed ~(基础DP)打印路径的上升子序列
InputInput 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.
OutputYour 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 题意是给你一串数据老鼠的体重和速度,
要你找到一组最长的数组证明体重越大速度越小
这个非常简单就是和求一个最长的上升子序列差不多
这题还有一个要求是打印路径。
所以就要继续前一个数据的下标。
这题细节方面好恶心,
打印路径的时候,只能按照体重最小打印到体重最大的顺序
不能从体重最大到体重最小。(因为这个WA了无数遍)
还有一个恶心的点是数据读入的时候,不知道如何终止数据的读入。
这里需要用的文件的操作,第一次遇到这种题目,表示真心恶心。
一个水题,弄成这样坑爹的题目也不容易
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
using namespace std; const int mod = 1e9 + ;
const int maxn = 1e4 + ;
struct node {
int w, f, id;
} a[maxn] ;
struct ndoe1 {
int num, pre;
} dp[maxn];
int cmp(node a, node b) {
return a.w < b.w;
}
int path[maxn];
int main() {
int k = ;
while(scanf("%d%d", &a[k].w, &a[k].f) != EOF ) {
a[k].id = k + ;
dp[k].num = ;
dp[k].pre = ;
k++;
}
sort(a, a + k, cmp );
int ans = -, temp = ;
for (int i = ; i < k ; i++ ) {
for (int j = ; j < i ; j++) {
if (a[i].w > a[j].w && a[i].f < a[j].f ) {
if (dp[i].num < dp[j].num + ) {
dp[i].num = dp[j].num + ;
dp[i].pre = j;
}
}
}
if (dp[i].num > ans) {
ans = dp[i].num;
temp = i;
}
}
printf("%d\n", ans);
for (int i = ; i < ans ; i++ ) {
path[i] = temp;
temp = dp[temp].pre;
}
for (int i = ans - ; i >= ; i-- ) {
printf("%d\n", a[path[i]].id);
}
return ;
}
FatMouse's Speed ~(基础DP)打印路径的上升子序列的更多相关文章
- FatMouse's Speed 基础DP
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- zoj 1108 FatMouse's Speed 基础dp
FatMouse's Speed Time Limit: 2 Seconds Memory Limit:65536 KB Special Judge FatMouse believe ...
- zoj 1108 FatMouse's Speed 基础dp
FatMouse's Speed Time Limit: 2 Seconds Memory Limit:65536 KB Special Judge FatMouse believe ...
- 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(LIS+记录路径)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【noi 2.6_2000】&【poj 2127】 最长公共子上升序列 (DP+打印路径)
由于noi OJ上没有Special Judge,所以我是没有在这上面AC的.但是在POJ上A了. 题意如标题. 解法:f[i][j]表示a串前i个和b串前j个且包含b[j]的最长公共上升子序列长度 ...
- HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- [HDOJ1160]FatMouse's Speed(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...
随机推荐
- 使用MBROSTool 工具制作本地硬盘F3救急模式的方法总结
前面写了一篇使用MBROSTool 工具制作本地硬盘多启动盘的方法总结.里面就是可以把一些系统安装到硬盘上面方便使用,比如安装PE到硬盘,不过启动的时候会先进入多UDm菜单,然后选择[启动本地系统]后 ...
- 【django之分页器】
一.什么是分页功能 二.Django的分页器(paginator) 语法: paginator = Paginator(book_list, 8) #8条一页print("count:&qu ...
- js正则《转载收藏》
\:转义字符.'\\n'匹配\n ^:开始位置.'^[0-9]'匹配以数字开头的字符,可以匹配'88DC',不可匹配'DC88' $:结束位置.'[0-9]$'匹配以数字结尾的字符,可以匹配'ab12 ...
- python学习03-数据类型
一.基本数据类型--数字 布尔型 bool型只有两个值:True和False 之所以将bool值归类为数字,是因为我们也习惯用1表示True,0表示False. 以下是布尔值是False的各种情况: ...
- 分别用EasyAR和Vuforia开发AR(入门级)
最近在一边学习谷歌TensorFlow,一边在做些简单的AR demo,在此总结下学习经验(自学的过程异常痛苦啊,还有总会有好人会在社区分享经验,这就是前人栽树,后人乘凉呐) 自从任天堂推出<精 ...
- ASP.NET MVC编程——模型
1 ViewModel 是一种专门提供给View使用的模型,使用ViewModel的理由是实体或领域模型所包含的属性比View使用的多或少,这种情况下实体或领域模型不适合View使用. 2模型绑定 默 ...
- Mycat 分片规则详解--固定 hash 分片
实现方式:该算法类似于十进制的求模运算,但是为二进制的操作,例如,取 id 的二进制低 10 位 与 1111111111 进行 & 运算 优点:这种策略比较灵活,可以均匀分配也可以非均匀分配 ...
- 笔记:Maven 依赖及配置详解
dependencies 配置节,主要用于配置项目依赖的其他包,其子节点 dependency 用来配置具体依赖包,有groupId.artifactId.version.scope等子节点来说明,配 ...
- 测试&标准说明文章
这是一篇测试用文章,主要想想怎么把纸质本上的习惯沿袭到博客上来 #coding=utf-8 import sys def main(): print "this is some code f ...
- jmeter连接Mysql数据库测试性能初探
Jmeter mysql性能测试演示 1. Jmeter是java开发的,jmeter连接mysql数据库当然需要jdbc驱动,这个可以在网上下载mysql-connector-java包,然后解压 ...