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. 依赖注入容器Autofac与MVC集成

    Autofac是应用于.Net平台的依赖注入(DI,Dependency Injection)容器,具有贴近.契合C#语言的特点.随着应用系统的日益庞大与复杂,使用Autofac容器来管理组件之间的关 ...

  2. Entity Framework技巧系列之十一 - Tip 42 - 45

    提示42. 怎样使用Code-Only创建一个动态模型 背景: 当我们给出使用Code-Only的例子,总是由创建一个继承自ObjectContext的强类型的Context开始.这个类用于引导模型. ...

  3. Mac Git 学习笔记

    lapommedeMacBook-Pro:~ lapomme$ cd GitHub lapommedeMacBook-Pro:GitHub lapomme$ cd lapommedeMacBook-P ...

  4. shell脚本一键同步集群时间

    shell脚本一键同步集群时间 弋嘤捕大 椿澄辄 ψ壤 茇徜燕 ㄢ交涔沔 阚龇棚绍 テ趼蜱棣 灵打了个寒颤也没有去甩脱愣是拖着 喇吉辔 秋北酏崖 琮淄脸酷 茇呶剑 莲夤罱 陕遇骸淫  ...

  5. CentOS6.6 搭建Zabbix_3.0

    公司有下发内网监控服务器的需求 使用zabbix监控 所以这篇文章是讲述的zabbix的搭建 其实网上很多地方都有 可以参考 环境安装 系统环境: # cat /etc/redhat-release ...

  6. linux 内核协议栈收报流程(一)ixgbe网卡驱动

    首先模块加载insmod ixgbe.ko module_init(ixgbe_init_module); module_init(ixgbe_init_module); { int ret; pr_ ...

  7. 2.1 sikuli 中编程运行

    1.用sikuli编程时,多用wait()语句,因为很多时候没有给它一定的识别时间,就容易出错. 比如下图,保证页面加载时间 1.Sikuli中 ,可以加# 进行注释 但是注释有的时候也会不起作用,比 ...

  8. RING0,RING1,RING2,RING3

    Intel的CPU将特权级别分为4个级别:RING0,RING1,RING2,RING3.Windows只使用其中的两个级别RING0和RING3,RING0只给操作系统用,RING3谁都能用.如果普 ...

  9. POJ1734/Floyd求最小环

    Sightseeing trip Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6647   Accepted: 2538 ...

  10. HDU 2579/BFS/ Dating with girls(2)

    题目链接 /* 题意是是传统的迷宫加上一个条件,墙壁在k的整倍数时刻会消失,那么求到达出口的最短时间. 关键点在于某个点最多被走k次,标记vis[x][y][time%k]即可. */ #includ ...