zoj 1108 FatMouse's Speed 基础dp
Time Limit: 2 Seconds Memory Limit:65536 KB Special Judge
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 Specification
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 Specification
Your program should output a sequence of lines of data; the first line should contain a numbern; the remainingn lines should each contain a single positive integer (each one representing a mouse). If thesen integers arem[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
Output for Sample Input
4
4
5
9
7
天啊,好可耐的老鼠,抱抱。
为达到DP的无后续性,以其中一个为关键词排序,然后最长上升subque。
从后向前不需要倒序输出。从前向后不要忘记倒序输出:
用 数组记录或者递归实现。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
int m,x,y;
struct in{
int w,s,pos,pre,num;
}a[];
int b[];
bool cmp(in a,in b){
return a.w<b.w;
}
void _solve()
{
for(int i=;i<=m;i++){
for(int j=;j<i;j++){
if(a[i].w>a[j].w&&a[i].s<a[j].s)
if(a[i].num<a[j].num+){
a[i].num=a[j].num+;
a[i].pre=j;
}
}
}
int M=,L=;
for(int i=m;i>=;i--)
{
if(a[i].num>M) {
M=a[i].num;
L=i;
}
}
printf("%d\n",M);
int t=;
while(L>){//也可以试试调用递归来倒序输出
b[++t]=a[L].pos;
L=a[L].pre;
}
for(int i=t;i>=;i--) printf("%d\n",b[i]);
return ;
}
int main()
{
while(~scanf("%d%d",&x,&y))
{
a[++m].w=x;
a[m].s=y;
a[m].pos=m;
a[m].num=;
}
sort(a+,a+m+,cmp);
_solve();
return ;
}
zoj 1108 FatMouse's Speed 基础dp的更多相关文章
- zoj 1108 FatMouse's Speed 基础dp
FatMouse's Speed Time Limit: 2 Seconds Memory Limit:65536 KB Special Judge FatMouse believe ...
- FatMouse's Speed 基础DP
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- ZOJ 1108 FatMouse's Speed (HDU 1160) DP
传送门: ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=108 HDU :http://acm.hdu.edu.cn/s ...
- [HDOJ1160]FatMouse's Speed(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse believes that the fatter a mouse is, th ...
- HDU 1160 FatMouse's Speed(DP)
点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...
- HDU 1160 FatMouse's Speed LIS DP
http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...
- hdu FatMouse's Speed 动态规划DP
动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3§ionid ...
- HDU 1160 FatMouse's Speed (sort + dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...
- HDU FatMouse's Speed 基本DP
题意:要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数.Special Judge 思路:先按体重由小到大排序,再找最长速度递减序列. 转移方程:mou[i].w> ...
随机推荐
- Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks论文理解
一.创新点和解决的问题 创新点 设计Region Proposal Networks[RPN],利用CNN卷积操作后的特征图生成region proposals,代替了Selective Search ...
- typeof
1.用法 typeof num typeof(num) 2.返回值 "number"."string"."boolean"." ...
- js 几个重要的特性
背景: 语法借鉴 java 函数借鉴 scheme 原型继承借鉴 self 正则表达式借鉴 Perl 1.动态语言 函数的定义和调用 形参与实参不需要一致 形参可由 argu ...
- bcompare Linux版 无限试用
需要root权限. # mv /usr/bin/bcompare /usr/bin/bcompare.real # cat /usr/bin/bcompare #!/bin/sh rm " ...
- 手把手教你开发jquery插件(三)
First, i want to add options to Tabs constructor like this: var tabs = $("div.tabs").tabs( ...
- 使用 Python 的 Socket 模块构建一个 UDP 扫描工具
译文:oschina 英文:bt3gl 当涉及到对一些目标网络的侦察时,出发点无疑是首先发现宿主主机.这个任务还可能包含嗅探和解析网络中数据包的能力. 几周前,我曾经谈到了如何使用Wireshark来 ...
- Android设计模式之单例模式
定义 单例模式是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例的特殊类.通过单例模式可以保证系统中一个类只有一个实例 . 单例模式是设计模式中最简单的形式之一.这一模式的目的是使得类的一 ...
- homestead 添加新站点
homestead 添加站点的时候遇到了坑,这里记录下来,也顺便给大家一个参考. 1. 首先修改homestead.yaml文件(虽然你有可能不知道这个文件在哪,但是我也不会帮你找的.) 2. 接着修 ...
- 批量kill Linux环境下的任务
批量kill Linux服务器的进程可以通过ps grep aws xargs 进行结合来完成 比如要kill 全部test.sh 的进程 ps -ef |grep "test.sh ...
- Error when clicking other button after displaying Popup window(转)
原文地址:Error when clicking other button after displaying Popup window Hi, I'm developing a custom page ...