FatMouse's Speed

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

Source

 
 //2017-04-04
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; struct node
{
int w, s, pos;
bool operator<(node x)
{
return w < x.w;
}
}mice[];
int dp[], pre[];//dp[i]表示前i只老鼠的最长下降子序列 void print(int pos)
{
if(pos == -)return ;
print(pre[pos]);
printf("%d\n", mice[pos].pos);
} int main()
{
int n = , w, s;
memset(pre, -, sizeof(pre));
while(scanf("%d%d", &w, &s)!=EOF)
{
mice[n].w = w;
mice[n].s = s;
mice[n].pos = n+;
n++;
}
sort(mice, mice+n);
int pos = -, mx = ;
for(int i = ; i < n; i++){
dp[i] = ;
for(int j = ; j < i; j++){
if(mice[j].w < mice[i].w && mice[j].s > mice[i].s){
if(dp[j]+ > dp[i]){
dp[i] = dp[j]+;
pre[i] = j;
}
}
}
if(dp[i] > mx){
mx = dp[i];
pos = i;
}
}
printf("%d\n", mx);
print(pos);
return ;
}

HDU1160(KB12-J DP)的更多相关文章

  1. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) J dp 背包

    J. Bottles time limit per test 2 seconds memory limit per test 512 megabytes input standard input ou ...

  2. J Dp

    <span style="color:#000099;">/* ____________________________________________________ ...

  3. C. Multiplicity 简单数论+dp(dp[i][j]=dp[i-1][j-1]+dp[i-1][j] 前面序列要满足才能构成后面序列)+sort

    题意:给出n 个数 的序列 问 从n个数删去任意个数  删去的数后的序列b1 b2 b3 ......bk  k|bk 思路: 这种题目都有一个特性 就是取到bk 的时候 需要前面有个bk-1的序列前 ...

  4. Andrew Stankevich's Contest (21) J dp+组合数

    坑爹的,,组合数模板,,, 6132 njczy2010 1412 Accepted 5572 MS 50620 KB C++ 1844 B 2014-10-02 21:41:15 J - 2-3 T ...

  5. 牛客集训第七场J /// DP

    题目大意: 在矩阵(只有52种字符)中找出所有不包含重复字符的子矩阵个数 #include <bits/stdc++.h> #define ll long long using names ...

  6. hdu1160 dp

    hdu1160 题意:给出很多老鼠的数据,分别是它们的体重和跑速,为了证明老鼠越重跑得越慢,要找一组数据,由若干个老鼠组成,保证老鼠的体重依次增加而跑速依次减小,问这组数据最多能有多少老鼠,并按体重从 ...

  7. hdu 4049 2011北京赛区网络赛J 状压dp ***

    cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...

  8. 2017 ICPC区域赛(西安站)--- J题 LOL(DP)

    题目链接 problem description 5 friends play LOL together . Every one should BAN one character and PICK o ...

  9. codeforces gym 100947 J. Killing everything dp+二分

    J. Killing everything time limit per test 4 seconds memory limit per test 64 megabytes input standar ...

随机推荐

  1. XAMPP中MySQL无法启动解决办法

    如图 问题出在mysql的路径上,其实报错已经讲得听清楚了 预期应该是这样 结果却是这样 所以解决办法当然就是修改这个路径,出现这个报错原因大多因为之前电脑装过mysql,所以电脑默认启动是原来的my ...

  2. jquery中的ajax请求,阻塞ui线程的解决方案(自己总结的demo)

    /*****************************************************/ function getAjaxData(url,data){ showLoading( ...

  3. redhat_6.5下载地址

    redhat官方下载(需要注册帐号+订阅/申请试用方可下载) https://access.redhat.com/downloads/ 网络资源:附RHEL 6.5安装文件MD5及SHA-256:一. ...

  4. oracle exp imp日常使用

    http://www.cnblogs.com/ningvsban/archive/2012/12/22/2829009.html http://www.cnblogs.com/mq0036/archi ...

  5. Django设置联合唯一约束 -- migrate时报错处理

    异常信息: a unique database constraint for 2 or more fields together 场景描述: 对于ORM中多对多关系的中间表,如果该关系表是手动创建的, ...

  6. android 回调函数使用简介

    //1---定义回调函数 public interface GirdMenuStateListener { void onSuccess(); void onError(); } //2---使用的地 ...

  7. CentOS7.x编译安装nginx,实现HTTP2

    网站使用HTTP2有助于网站加速及更安全,要配置HTTP2必须满足两个条件:①openssl的版本必须在1.0.2e及以上.②nginx的版本必须在1.9.5以上 一.准备工作  配置HTTP2之前需 ...

  8. (转)Python中的上下文管理器和Tornado对其的巧妙应用

    原文:https://www.binss.me/blog/the-context-manager-of-python-and-the-applications-in-tornado/ 上下文是什么? ...

  9. 使用Docker发布应用

    新建spring boot应用demo-docker,添加web依赖 <dependency> <groupId>org.springframework.boot</gr ...

  10. CDN基本工作过程

    看了一些介绍CDN的文章,感觉这篇是讲的最清楚的. 使用CDN会极大地简化网站的系统维护工作量,网站维护人员只需将网站内容注入CDN的系统,通过CDN部署在各个物理位置的服务器进行全网分发,就可以实现 ...