FatMouse's Speed

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

题意:输入若干个mice的weight和speed,然后要求weight递增和speed递减的最长序列,然后输出分别是那几个

卡死了被这题,突然最长单调递增都不会写了=_=

将speed按照递减排序自后就是找weight的单调递增了...只不过还有记录一下是由那个推过来的,本来想写链表结果不会写了=_=,用一个数组记录也行,找到当前这个是由哪一个递推过来的,然后呢..其实这就是倒叙了已经,然后我却直接输出了wa了一番,因为忘记了+1,因为数组是从0开始的,弄得都混乱了,然后又浪费了20分钟的查错。

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = + ;
int n;
int dp[N];
vector<int> id_set[N];
struct Mouse
{
int weight, speed;
int id;
};
Mouse mice[N];
int cmp(Mouse x, Mouse y)
{
return x.speed > y.speed;
}
void solve()
{
memset(dp, , sizeof(dp));
for(int i = ; i <= n; i++)
id_set[i].clear();
dp[] = ;
int last_loca = ;
id_set[].push_back();
int ans = ;
for(int i = ; i <= n; i++)
{
int maxn = , pos = i;
for(int j = i - ; j >= ; j--)
{
if(mice[i].weight > mice[j].weight && maxn < dp[j] && mice[i].speed != mice[j].speed) //严格递减,所以speed不能相等
{
maxn = dp[j];
pos = j;
}
}
dp[i] = maxn + ;
id_set[i].push_back(pos);
if(ans < dp[i])
{
ans = dp[i];
last_loca = i;
}
}
printf("%d\n", ans);
stack<int> temp;
for(int i = ; i < ans; i++)
{
//printf("%d %d %d\n", mice[last_loca].weight, mice[last_loca].speed, mice[last_loca].id);
temp.push(mice[last_loca].id);
last_loca = id_set[last_loca][];
}
while(!temp.empty())
{
int tempx = temp.top();
temp.pop();
printf("%d\n", tempx + );
}
}
int main()
{
n = ;
while(scanf("%d%d", &mice[n].weight, &mice[n].speed) != EOF)
{
mice[n].id = n;
n++;
}
sort(mice, mice + n, cmp);
// cout << "--------------" << endl;
//for(int i = 0; i < n; i++)
// cout << mice[i].id << " " << mice[i].weight << " " << mice[i].speed << endl;
solve();
return ;
}

HD1160FatMouse's Speed(最长单调递增子序列)的更多相关文章

  1. 动态规划-最长单调递增子序列(dp)

    最长单调递增子序列 解题思想:动态规划 1.解法1(n2) 状态:d[i] = 长度为i+1的递增子序列的长度 状态转移方程:dp[i] = max(dp[j]+1, dp[i]); 分析:最开始把d ...

  2. [C++] 动态规划之矩阵连乘、最长公共子序列、最大子段和、最长单调递增子序列、0-1背包

    一.动态规划的基本思想 动态规划算法通常用于求解具有某种最优性质的问题.在这类问题中,可能会有许多可行解.每一个解都对应于一个值,我们希望找到具有最优值的解. 将待求解问题分解成若干个子问题,先求解子 ...

  3. [dp]最长单调递增子序列LIS

    https://www.51nod.com/tutorial/course.html#!courseId=12 解题关键: 如果将子序列按照长度由短到长排列,将他们的最大元素放在一起,形成新序列$B\ ...

  4. poj1631Bridging signals(最长单调递增子序列 nlgn)

    Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12251   Accepted: 6687 ...

  5. NYOJ17 最长单调递增子序列 线性dp

    题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=17 分析: i=1 dp[i]=1 i!=1 dp[i]=max(dp[j]+1) ...

  6. nyoj 单调递增子序列(二)

    单调递增子序列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 给定一整型数列{a1,a2...,an}(0<n<=100000),找出单调递增最长 ...

  7. nyist oj 214 单调递增子序列(二) (动态规划经典)

    单调递增子序列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描写叙述 ,a2...,an}(0<n<=100000).找出单调递增最长子序列,并求出其长度 ...

  8. ny214 单调递增子序列(二) 动态规划

    单调递增子序列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 给定一整型数列{a1,a2...,an}(0<n<=100000),找出单调递增最长子序 ...

  9. nyoj 214 单调递增子序列(二)

    单调递增子序列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 ,a2...,an}(0<n<=100000),找出单调递增最长子序列,并求出其长度. ...

随机推荐

  1. Ext.NET-基础篇

    概述 本文介绍Ext.NET的基本概念,安装配置.布局以及容器,最后介绍了DirectEvents.DirectMethod.Listener,并提供了示例代码. 示例代码下载地址>>&g ...

  2. [转]史上最全的CSS hack方式一览

    做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我们会极不情愿的使用这个不太友好的方式来达到大家要求的页面表现.我个人是不太推荐使用hack的,要知道 ...

  3. O2O营销模式(Online To Offline)

    什么是O2O营销模式 O2O营销模式又称离线商务模式,是指线上营销线上购买带动线下经营和线下消费.O2O通过打折.提供信息.服务预订等方式,把线下商店的消息推送给互联网用户,从而将他们转换为自己的线下 ...

  4. VS代码管理插件AnkhSvn

    下载AnKHSvn软件,启动VS,源代码管理工具选择AnKHSvn 在视图-〉其它窗口-〉Pending Change->提交变化的更改

  5. name after, name for, name as

    name after, name for, name as name after是一个常见用法  :  1.Her parents named her Sophia after her grandmo ...

  6. android studio用法笔记

    1.每次创建新工程的时候,就会“check sdk repository”,然而这个进度条一动不动,解决方法:file>setting>plugins>sdk updater禁用就行 ...

  7. 一键系统优化15项脚本,适用于Centos6.x

    #!/bin/sh ################################################ #Author:nulige # qqinfo:1034611705 # Date ...

  8. Oracle之物化视图

    来源于:http://www.cnblogs.com/Ronger/archive/2012/03/28/2420962.html 近期根据项目业务需要对oracle的物化视图有所接触,在网上搜寻关于 ...

  9. SharedPreferences

    除了SQLite数据库外,SharedPreferences也是一种轻型的数据存储方式,它是Android数据持久化方法中最简单的一种. 其本质是基于XML文件存储key-value键值对数据,通常用 ...

  10. 一个很好的UML工具

    访问地址:www.visual-paradigm.com 工具使用帮助文档地址: http://www.visual-paradigm.com/support/documents/vpumluserg ...