FatMouse's Speed

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13643    Accepted Submission(s): 6011
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
 
以weight为第一元素从小到大排序,相同时speed为第二元素从大到小,状态转移方程为
dp[i] = 1     dp[i] = max(dp[i],dp[j]+1); (j<i,p[j].weight>p[i].weight,p[j].speed<p[i].speed);
 #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = ;
struct node{
int weight;
int speed;
int num;
};
node p[maxn];
int dp[maxn];
bool cmp(node A,node B){
if(A.weight != B.weight) return A.weight<B.weight;
else return A.speed>B.speed;
}
void solve(){
int k = ,x,y;
while(scanf("%d%d",&x,&y)!=EOF){
p[k].weight = x;
p[k].speed = y;
p[k].num = k;
k++;
}
sort(p+,p+k+,cmp);
int ans = ;
for(int i = k;i>=; i--){
dp[i] = ;
for(int j = i; j<=k; j++){
if(p[j].weight>p[i].weight&&p[j].speed<p[i].speed){
dp[i] = max(dp[i],dp[j]+);
}
}
ans = max(ans,dp[i]);
}
printf("%d\n",ans);
for(int i = ; i<=k; i++){
if(dp[i] == ans){
printf("%d\n",p[i].num);
ans--;
}
if(ans == ) break;
}
}
int main()
{
solve();
return ;
}

FatMouse's Speed 基础DP的更多相关文章

  1. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  2. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  3. [HDOJ1160]FatMouse's Speed(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...

  4. HDU 1160 FatMouse's Speed(DP)

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

  5. HDU 1160 FatMouse's Speed LIS DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...

  6. hdu FatMouse's Speed 动态规划DP

    动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid ...

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

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

  8. HDU FatMouse's Speed 基本DP

    题意:要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数.Special Judge 思路:先按体重由小到大排序,再找最长速度递减序列. 转移方程:mou[i].w> ...

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

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

随机推荐

  1. HDU2504:又见GCD

    Problem Description 有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b.若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c.   Input ...

  2. JavaScript焦点事件、鼠标事件和滚轮事件使用详解

    网址:http://www.jb51.net/article/78094.htm

  3. 暴力+树状数组维护 Codeforces Round #378 (Div. 2) C

    题目大意:给你一个长度为n的数组a,然后数值大的可以合并数值小的,且合并了以后该数组的长度-1.给你一个长度为k目标数组b,问,是否可以从a数组变到b数组,是就yes并且输出步骤.否就输出no 思路: ...

  4. 【dp 背包变形】 poj 1837

    #include <cstdio> #include <memory.h> #include<iostream> using namespace std; ][]; ...

  5. 【字母全排列】 poj 1256

    深搜   注意与STL模版的去重函数唯一的区别就是有去重. #include <iostream> #include <cstdio> #include <string. ...

  6. JNI调用问题(部分机型崩溃)

    1.今日测试发现在部分手机上游戏会崩溃,通过logcat日志发现是jni调用问题(我猜测) 错误日志中有如下语句: trying to work around app JNI bugs, but di ...

  7. CURL C++网络延时或者最低网速下载设置

    1.起因: 下载游戏更新包客户反应更新时间太久,要求我们网速比较低的时候就不要更新 2.解决: 因为之前用的是curl下载,所以在查看了curl.h里面的说明后使用了以下两个option实现了下载时最 ...

  8. Openlays 3 绘制基本图形

    <body> <div id="menu"> <label>几何图形类型:</label> <select id=" ...

  9. Hibernate 系列教程4-单向多对一

    项目图片 hibernate.cfg.xml <mapping resource="com/jege/hibernate/one/way/manytoone/User.hbm.xml& ...

  10. Number Sequence HDU 1711 KMP 模板

    题目大意:两个数组匹配,求子串首次出现的位置. 题目思路:数组长度,比较大,朴素算法的时间复杂度为 m*n超时.KMP的时间复杂度为m+n可行. #include<iostream> #i ...