http://acm.hdu.edu.cn/showproblem.php?pid=1160

FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12338    Accepted Submission(s): 5405
Special Judge

Problem Description
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<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm> using namespace std;
#define N 10005
#define oo 0x3f3f3f3f /** 感觉有点用导弹防御的思想
每次记录从 0 到 i 的最长个数
并用 pre[i] 记录 i 点是从哪个点过来的 **/ /// number 是记录它原来的位置 struct node
{
int w, s, number;
}a[N]; /// pre[] 是个很好的记录方式,可以记录它的是从哪个过来的(它的上一步) int dp[N], pre[N]; /// 先按 w 从小到大排, 再按 s 从大到小排
int cmp(node n1, node n2)
{
if(n1.w!=n2.w)
return n1.w < n2.w;
return n1.s > n2.s;
} int main()
{
int i=, j, n; memset(a, , sizeof(a));
memset(dp, , sizeof(dp)); while(scanf("%d%d", &a[i].w, &a[i].s)!=EOF)
{
a[i].number = i;
i++;
} n=i;
sort(a+, a+i+, cmp); /**
for(i=1; i<n; i++)
printf("%d %d %d\n", a[i].number, a[i].w, a[i].s);
**/ for(i=; i<n; i++)
{
pre[i] = i;
dp[i] = ;
for(j=; j<i; j++)
{
if(a[i].w!=a[j].w && a[i].s<a[j].s)
{
if(dp[i]<dp[j]+)
{
pre[i] = j;
dp[i] = dp[j] + ;
}
}
}
} int Max=-oo, index=; for(i=; i<n; i++)
{
if(dp[i]>Max)
{
Max = dp[i];
index = i;
}
} printf("%d\n", Max);
i=;
int b[N]={};
while(pre[index]!=index)
{
b[i++] = a[index].number;
index = pre[index];
} printf("%d\n", a[index].number);
for(j=i-; j>=; j--)
printf("%d\n", b[j]); return ;
}

(最长上升子序列 并记录过程)FatMouse's Speed -- hdu -- 1160的更多相关文章

  1. FatMouse's Speed HDU - 1160 最长上升序列, 线性DP

    #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> usi ...

  2. ZOJ 1108 FatMouse's Speed (HDU 1160) DP

    传送门: ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=108 HDU :http://acm.hdu.edu.cn/s ...

  3. HDU - 1160 最长上升子序列以及记录路径

    题意:第一列,给出老鼠的重量,第二列,给出老鼠的速度,要证明老鼠的重量越大,速度越小,给出最多老鼠的数量,并说明第几只. 思路:先将老鼠按照重量从大到小排序,然后速度是从小到大,求最长上升子序列,学习 ...

  4. CSU 1225 最长上升子序列并记录其个数

    ;j<i;j++){ if(h[i] > h[j]){ ) cnt[i]+=cnt[j]; ) len[i] = len[j] + , cnt[i] = cnt[j]; } //身高相同的 ...

  5. - > 动规讲解基础讲解七——最长单增子序列

    (LIS Longest Increasing Subsequence)给定一个数列,从中删掉任意若干项剩余的序列叫做它的一个子序列,求它的最长的子序列,满足子序列中的元素是单调递增的. 例如给定序列 ...

  6. HDU 1160 FatMouse's Speed(DP)

    点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...

  7. HDU 1160 FatMouse's Speed 动态规划 记录路径的最长上升子序列变形

    题目大意:输入数据直到文件结束,每行两个数据 体重M 和 速度V,将其排列得到一个序列,要求为:体重越大 速度越低(相等则不符合条件).求这种序列最长的长度,并输出路径.答案不唯一,输出任意一种就好了 ...

  8. HDU - 1503 最长公共子序列记录路径

    题意:先给两个水果的名字然后得出一个最短的序列包含这两个词. 思路:我一开始的思路是先求出最长公共子序列,然后做一些处理将其他的部分输出来:两种水果的字符串和最长公共子序列的字符串这三个字符串做对比, ...

  9. HDU 1160 FatMouse's Speed (最长上升子序列)

    题目链接 题意:n个老鼠有各自的重量和速度,要求输出最长的重量依次严格递增,速度依次严格递减的序列,n最多1000,重量速度1-10000. 题解:按照重量递增排序,找出最长的速度下降子序列,记录序列 ...

随机推荐

  1. Android.API.Context.getFilesDir()

    1. Context.getFilesDir() http://developer.android.com/reference/android/content/Context.html#getFile ...

  2. Android.Tools.Summary

    Android平台上工具的总结 每个工具的详细使用和深入理解参考每个工具相关的blog. 1. Android SDK中提供的工具 http://developer.android.com/tools ...

  3. Python.Books

    Flask 1. Flask Web Development Miguel Grinberg April 2014 2. Flask Framework Cookbook Shalabh Aggarw ...

  4. Expressions入门示例

    学习表达式的入门例子,前提是要对委托有一定的了解,泛型明白一些.using System; using System.Linq; using System.Linq.Expressions; usin ...

  5. libpcap 库使用(三)

    1.为了使收到的报文尽快给我们的处理程序,需要设置成immediate模式: int pcap_set_immediate_mode(pcap_t *p, int immediate_mode);

  6. MSI-X 之有别于MSI

    转自: https://www.cnblogs.com/helloworldspace/p/6760718.html MSI-X Capability结构 MSI-X Capability中断机制与M ...

  7. 没加载redis类,却可以实例化redis

    原因:phpinfo里面已有redis扩展

  8. 判断某个字符串里面是否包含caoyang 这个字符串?

    $string = 'Lorem ipsum dolor sit amet'; $preg = '/caoyang/'; $status = preg_match($preg, $string,$ma ...

  9. [Robot Framework] Robot Framework里面的变量怎么知道是在哪里定义的?

    看变量在哪里定义的:Ctrl+Alt+Space

  10. flask 中文编码解码

    process.append("中文") print(process) # return Response(json.dumps(process), mimetype='appli ...