FatMouse's Speed

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description: 
prayerhgq  (2015-07-28)
System Crawler  (2015-09-05)

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 <cstdio>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <climits>
using namespace std; const int SIZE = ;
struct Node
{
int pos;
int weight,speed;
int front,num;
}DP[SIZE]; bool comp(const Node & r_1,const Node & r_2);
int main(void)
{
int count = ; while(scanf("%d%d",&DP[count].weight,&DP[count].speed) != EOF)
{
DP[count].pos = count;
DP[count].num = ;
count ++;
}
sort(DP,DP + count,comp); int max = ,max_loc = ;
for(int i = ;i < count;i ++)
{
DP[i].front = i;
for(int j = ;j < i;j ++)
if(DP[i].weight > DP[j].weight && DP[i].speed < DP[j].speed)
if(DP[i].num < DP[j].num)
{
DP[i].num = DP[j].num;
DP[i].front = j;
if(max < DP[i].num + )
{
max = DP[i].num + ;
max_loc = i;
}
}
DP[i].num ++;
} int temp[SIZE];
count = ;
while()
{
temp[count] = max_loc;
if(max_loc == DP[max_loc].front)
{
count ++;
break;
}
max_loc = DP[max_loc].front;
count ++;
}
printf("%d\n",max);
for(int i = count - ;i >= ;i --)
printf("%d\n",DP[temp[i]].pos + ); return ;
} bool comp(const Node & r_1,const Node & r_2)
{
return r_1.weight < r_2.weight;
}

怒刷DP之 HDU 1160的更多相关文章

  1. 怒刷DP之 HDU 1257

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. 怒刷DP之 HDU 1260

    Tickets Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  3. 怒刷DP之 HDU 1176

    免费馅饼 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  4. 怒刷DP之 HDU 1087

    Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64 ...

  5. 怒刷DP之 HDU 1114

    Piggy-Bank Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

  6. 怒刷DP之 HDU 1069

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. 怒刷DP之 HDU 1024

    Max Sum Plus Plus Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. 怒刷DP之 HDU 1029

    Ignatius and the Princess IV Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d &a ...

  9. HDU 1160 DP最长子序列

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

随机推荐

  1. ASP.NET MVC- 在Area里使用RedirectToAction跳转出错的解决方法

    mvc使用Area分区开发后,存在不同Area之间的跳转,需要为每个区间添加Area规则,如下: 按 Ctrl+C 复制代码 using System.Web.Mvc; namespace web.A ...

  2. 未能加载文件或程序集"System.Data,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"或它的某一个依赖项。系统找不到指定的文件。

    sqlserver 2005打开出现无法正常访问数据,提示信息: 未能加载文件或程序集"System.Data,Version=2.0.0.0,Culture=neutral,PublicK ...

  3. C++学习之const整理总结

    1什么是const? (const类型)常类型是指使用类型修饰符const说明的类型,常类型的变量或对象的值是不能被更新的.(但可以偷梁换柱进行更新) 2为什么引入const? const 推出的初始 ...

  4. Hard problem

    1022: Hard problem Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 43   Solved: 12 Description The ...

  5. linux-用户建立及权限分配

    1.建立用户   useradd –d /usr/test -m test 此命令创建了一个用户test,用户主目录为/usr/test 2.设置用户密码 .修改自己的密码 passwd ,需要输入旧 ...

  6. Spket在Eclipse/MyEclipse下的安装和配置(图文教程)

    一.安装Spket 第一种方法:网上更新方式 1.插件首页:http://www.spket.com2.插件名称:Spket IDE3.更新连接(Update Site):http://www.spk ...

  7. Lockless Ring Buffer Design

    https://www.kernel.org/doc/Documentation/trace/ring-buffer-design.txt Lockless Ring Buffer Design == ...

  8. TCP连接(Time_Wait、Close_Wait)说明

    修改Time_Wait和CLOSE_WAIT时间 修改Time_Wait参数的方法 (在服务端修改)Windows下在HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlS ...

  9. SCVMM配置

    SCVMM添加工作组主机 1.准备一台物理主机并且安装WindowsServer 2012名为HV2(工作组不加域)接着添加hyper-v角色 2.把SCVMM1服务器上的SCVMM2012代理程序( ...

  10. CentOS 6.4安装本地yum源,并安装X Window System

    1.为DVD创建一个挂载目录 [root@localhost ~]# mkdir /media/CentOS 2.在Linux下挂载CentOS DVD(虚拟机挂载DVD不说了,应该都会) [root ...