FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20784    Accepted Submission(s): 9220
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

5

9

最长上升子序列问题变型,体重上升时要求速度下降(要按照这个顺序排序)并且要记录原始序号。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <stack>
using namespace std; struct Mouse
{
int w;
int v;
int on;
int parent;
}m[1001]; int cmp(Mouse n1, Mouse n2)
{
if(n1.w!=n2.w)
return n1.w < n2.w;
return n1.v > n2.v;
} bool cmp1( Mouse n1, Mouse n2 )
{
return n1.on < n2.on;
} int main()
{
int i, j, n;
int dp[1001] = { 0, };
i = 0;
while( ~scanf("%d %d", &m[i].w, &m[i].v) )
{
m[i].on = i + 1;
i++;
//if( i == 9 ) break;
}
n = i;
sort(m, m+n, cmp); for( i=0; i<n; i++ )
{
for( j=0; j<i; j++ )
{
if( m[j].w < m[i].w && m[j].v > m[i].v )
{
if( dp[j] + 1 > dp[i] )
{
dp[i] = dp[j] + 1;
m[i].parent = m[j].on;
}
}
}
if( dp[i] == 0 )
{
dp[i] = 1;
m[i].parent = -1;
}
} int x = 0;
int index;
for( i=0; i<n; i++ )
{
if( x <= dp[i] )
{
x = dp[i];
index = m[i].on;
}
}
cout << x << endl;
stack <int> S;
sort( m, m+n, cmp1 );
while( x-- )
{
S.push( index );
index = m[index-1].parent;
}
while( !S.empty() )
{
cout << S.top() << endl;
S.pop();
}
return 0;
}

HDU-1160-FatMouse's Speed(线性DP,LIS)的更多相关文章

  1. HDU 1160 FatMouse's Speed (sort + dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...

  2. HDU - 1160 FatMouse's Speed 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...

  3. HDU 1160 FatMouse's Speed(DP)

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

  4. HDU 1160 FatMouse's Speed ——(DP)

    又是那个lis变形的题目. 但是不好定义严格的比较符号,因此只能n^2去做.值得注意的一个是要先排序,因为可能可以先选后面的再选前面的,先排序的话就能够避免这个问题.但是要注意,因为要输出路径,所以要 ...

  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. HDU 1160 FatMouse's Speed (DP)

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  7. HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化

    HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...

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

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

  9. hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)

    题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...

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

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

随机推荐

  1. mybatis xml中常见配置demo

    新增: <insert id="insertSelective" parameterType="map" > insert into BS_CHNG ...

  2. linux环境下pdo加载问题

    报错信息信息 PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php5/20121212/pdo_mysql.so ...

  3. 事务传播性、隔离性与MVCC

    一.事务传播性 1.1 什么是事务的传播性 事务的传播性一般在事务嵌套时候使用,比如在事务A里面调用了另外一个使用事务的方法,那么这俩个事务是各自作为独立的事务执行提交,还是内层的事务合并到外层的事务 ...

  4. AES加解密

    AES加密类 <?php //php aes加密类 class AESMcrypt { public $iv = null; public $key = null; ; private $cip ...

  5. button作用类似于submit

    不想提交,可使用以下 <a href="javascript:;" >修改</a>

  6. jvm编译环境搭建 Debina篇

    这里参考了 <Java虚拟机精讲> <深入理解Java虚拟机 JVM高级特性与最佳实践> http://www.cnblogs.com/zxfdream/p/5411511.h ...

  7. DataStage 七、在DS中使用配置文件分配资源

    DataStage序列文章 DataStage 一.安装 DataStage 二.InfoSphere Information Server进程的启动和停止 DataStage 三.配置ODBC Da ...

  8. 20155230 2016-2017-2 《Java程序设计》第七周学习总结

    20155230 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 世界时:在1972年引入UTC之前,GMT与UT是相同的 格林威治标准时间(GMT),现已不 ...

  9. CentOS 7 装好系统一些优化

    1.禁用SELINUX vi /etc/sysconfig/selinux  设置为disabled 2.同步时间*/20 * * * * /usr/sbin/ntpdate pool.ntp.org ...

  10. ssh 无密码登录要使用公钥与私钥

    ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例. 有机器A(192.168.1.155),B(192.168.1.181).现想 ...