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. 

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)打印路径的上升子序列的更多相关文章

  1. FatMouse's Speed 基础DP

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  3. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  4. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDU 1160:FatMouse's Speed(LIS+记录路径)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. 【noi 2.6_2000】&【poj 2127】 最长公共子上升序列 (DP+打印路径)

    由于noi OJ上没有Special Judge,所以我是没有在这上面AC的.但是在POJ上A了. 题意如标题. 解法:f[i][j]表示a串前i个和b串前j个且包含b[j]的最长公共上升子序列长度 ...

  7. HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. 题解报告:hdu 1160 FatMouse's Speed(LIS+记录路径)

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  9. [HDOJ1160]FatMouse's Speed(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...

随机推荐

  1. Docker学习——pinpoint部署

    Pinpoint Install pinpoint-server 下载镜像 docker pull yous/pinpoint 查看镜像 docker images 启动容器 docker run - ...

  2. C++调用C方法

    //1,编译静态库 libtest.a gcc -c test.c -o test.o ar rc libtest.a test.o //2,编译main函数 g++ -o main main.cpp ...

  3. execCommand的复制

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  4. poj-1012-约瑟夫问题

    Description The Joseph's problem is notoriously known. For those who are not familiar with the origi ...

  5. 给我一台全新的服务器,使用nginx+gunicorn+supervisor部署django

    0.准备工作 在一台全新的服务器中新建用户以及用户的工作目录,之后的操作都以这个用户的身份进行,而不是直接用root. 举个栗子: 在服务器下新建用户rinka并赋予sudo权限 1) root登陆, ...

  6. SpringMvc环境搭建(配置文件)

    在上面的随笔里已经把搭建springmvc环境的基本需要的包都下下来了,拉下来就是写配置文件了. 下面左图是总的结构,右图是增加包 一.最开始当然是web.xml文件了,这是一个总的宏观配置 < ...

  7. iOS移动端直连数据库

    一个可以直接连接服务器MySQL的工具包(极不安全,如非特殊需求,不推荐使用) 这种直接连接服务器数据的方式是极为不安全的,但因为我们这个项目特殊情况,只在局域网内使用, 且只有一个pad对一台设备进 ...

  8. python全栈学习--day10(函数进阶)

    一,引言 现在我有个问题,函数里面的变量,在函数外面能直接引用么? def func1(): m = 1 print(m) print(m) #这行报的错 报错了:NameError: name 'm ...

  9. php设计模式八-----装饰器模式

    1.介绍: 装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其结构.这种类型的设计模式属于结构型模式,它是作为现有的类的一个包装. 这种模式创建了一个装饰 ...

  10. Leetcode 27——Remove Element

    Given an array and a value, remove all instances of that value in-place and return the new length. D ...