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. Python 一篇学会多线程

    多线程和多进程是什么自行google补脑,廖雪峰官网也有,但是不够简洁,有点晕,所以就整个简单的范例. 对于python 多线程的理解,我花了很长时间,搜索的大部份文章都不够通俗易懂.所以,这里力图用 ...

  2. python 结巴分词简介以及操作

    中文分词库:结巴分词 文档地址:https://github.com/fxsjy/jieba 代码对 Python 2/3 均兼容 全自动安装:easy_install jieba 或者 pip in ...

  3. POJ 2864

    #include <iostream> #define MAXN 600 using namespace std; int _m[MAXN][MAXN]; int main() { //f ...

  4. Googel 浏览器 模拟发送请求工具--Advanced REST Client

    Advanced REST Client是 Chrome 浏览器下的一个插件,通过它可以发送 http.https.WebSocket 请求.在 Chrome 商店下搜索 Advanced REST  ...

  5. GPS/轨迹追踪、轨迹回放、围栏控制

    折腾一个多月终于弄完了这个项目,起初都未曾接触GPS/轨迹追踪.轨迹回放.圈划围栏...等一些在百度地图或者Googel地图操作的一些业务,后端的业务相对来说简单点 cas单点登录,mongdb灵活的 ...

  6. tensorflow进阶篇-4(损失函数3)

    Softmax交叉熵损失函数(Softmax cross-entropy loss)是作用于非归一化的输出结果只针对单个目标分类的计算损失.通过softmax函数将输出结果转化成概率分布,然后计算真值 ...

  7. Postman入门

  8. java字节码文件

    查看字节码文件: javap  -verbose  HellloWorld.class

  9. 比特币算法——SHA256算法介绍

    SHA256是安全散列算法SHA(Secure Hash Algorithm)系列算法之一,其摘要长度为256bits,即32个字节,故称SHA256.SHA系列算法是美国国家安全局 (NSA) 设计 ...

  10. MongoDB学习3 $操作符表达式大全及实例

    from : http://blog.csdn.net/qq_16313365/article/details/58599253 1.查询和投影   1.1 比较操作符 $eq 语法:{ <fi ...