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> ...
随机推荐
- [js高手之路]Vue2.0基于vue-cli+webpack同级组件之间的通信教程
我们接着上文继续,本文我们讲解兄弟组件的通信,项目结构还是跟上文一样. 在src/assets目录下建立文件EventHandler.js,该文件的作用在于给同级组件之间传递事件 EventHandl ...
- 阿里云Maven地址
GFW 呵呵呵 下载几个jar要几个小时.....伤透了 直接替换国内阿里云的maven镜像地址 速度嗖嗖嗖的.... 配置 修改maven根目录下的conf文件夹中的setting.xml文件,内 ...
- CCIE-MPLS VPN-实验手册(上卷)
看完了看完了看完了,豪爽豪爽豪爽,一个月了,写得挺棒.总共14个mpls vpn的实验,为留下学习的痕迹,原封不动献出. CCIE实验手册 (路由部分-MPLSVPN基础篇) [CCIE] JUST ...
- Swing-JPopupMenu弹出菜单用法-入门
弹出菜单是GUI程序中非常常见的一种控件.它通常由鼠标右击事件触发,比如在windows系统桌面上右击时,会弹出一个包含“刷新”.“属性”等菜单的弹出菜单.Swing中的弹出菜单是JPopupMenu ...
- 201521123008《Java程序设计》第八周实验总结
1. 本周学习总结 2. 书面作业 本次作业题集集合 1.List中指定元素的删除(题目4-1) 1.1 实验总结 1.删除元素的时候从最后一个元素开始,避免删除元素后位置发生变化而导致有些元素没有删 ...
- 201521123055 《Java程序设计》第5周学习总结
1. 本章学习总结 2. 书面作业 Q1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句会出现错误?试改正该错误.并分析输出结果. 1. ...
- 201521123050 《Java程序设计》第5周学习总结
1. 本周学习总结 2. 书面作业 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句会出现错误?试改正该错误.并分析输出结果. 答:不 ...
- 201521123062《Java程序设计》第4周学习总结
1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. 多态定义:同种形态不同定义 类注释格式 继承,共同行为及属性 在instanceof检查过后 ...
- JAVA课程设计-猜数游戏 201521123017
1.团队课程设计博客链接 http://www.cnblogs.com/m1ng123/p/7056740.html 2.个人负责模块或任务说明 (1)文件读取和文件的存储 (2)提示板块的窗口设计 ...
- 201521123039 《java程序设计》第十周学习总结
1. 本周学习总结 2. 书面作业 本次PTA作业题集异常.多线程 finally 题目4-2 1.1 截图你的提交结果(出现学号) 1.2 4-2中finally中捕获异常需要注意什么? 总结:需要 ...