HDOJ --- 1160
FatMouse's Speed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8334 Accepted Submission(s): 3715
Special Judge
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.
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.
思路:DP水,先排序,然后直接比较。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<cstring>
#define MAX 1111
using namespace std;
class mouse{
public:
int w, v, id;
bool operator < (const mouse &a) const{
return w < a.w;
}
};
mouse m[MAX];
int dp[MAX], pre[MAX];
stack<int>s;
int main(){
int ans = , i = , j, k;
/* freopen("in.c", "r", stdin); */
while(~scanf("%d%d", &m[i].w, &m[i].v)) m[i].id = i, ++i;
while(!s.empty()) s.pop();
sort(m+, m+i);
for(int j = ;j < i;j ++) dp[j] = ;
memset(pre, , sizeof(pre));
m[].w = m[].v = ;
for(j = ;j < i;j ++){
for(k = ;k < j;k ++){
if(m[j].w > m[k].w && m[j].v < m[k].v){
if(dp[j] < dp[k] + ){
dp[j] = dp[k] + ;
pre[j] = k;
}
}
}
}
for(k = ;k < i;k ++){
if(ans < dp[k]){
ans = dp[k];
j = k;
}
}
printf("%d\n", ans);
s.push(m[j].id);
for(k = j;m[pre[k]].id;k = pre[k]) s.push(m[pre[k]].id);
while(!s.empty()){
printf("%d\n", s.top());
s.pop();
}
return ;
}
HDOJ --- 1160的更多相关文章
- Hdoj 1160.FatMouse's Speed 题解
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- dp入门题目
本文文旨,如题... 转载请注明出处... HDOJ 1176 免费馅饼 http://acm.hdu.edu.cn/showproblem.php?pid=1176 类似数塔,从底往上推,每次都是从 ...
- 【HDOJ】1160 FatMouse's Speed
DP. #include <stdio.h> #include <string.h> #include <stdlib.h> #define MAXNUM 1005 ...
- 杭电hdoj题目分类
HDOJ 题目分类 //分类不是绝对的 //"*" 表示好题,需要多次回味 //"?"表示结论是正确的,但还停留在模块阶 段,需要理解,证明. //简单题看到就 ...
- HDOJ 题目分类
HDOJ 题目分类 /* * 一:简单题 */ 1000: 入门用:1001: 用高斯求和公式要防溢出1004:1012:1013: 对9取余好了1017:1021:1027: ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
随机推荐
- win8.1企业版更新到win10解决方案
最近想把自己的win8.1更新成win10,发现月底就要免费更新了,由于我的电脑是企业版,官方不提供企业版的免费升级,所以用电脑管家或者360老是提示不对.我就百度了在注册表里面改成了专业版的,接着继 ...
- ubuntu 安装qt 5.1的各种错误
错误太多了,我就不一一说 了,直接一条命令搞定 sudo apt-:i386 libx11-:i386 libglib2.-:i386 libfreetype6:i386 libSM6:i386 li ...
- C++ 智能指针auto_ptr详解
1. auto_ptr 的设计动机: 函数操作经常依照下列模式进行: 获取一些资源 执行一些动作 释放所获取的资源 那么面对这些资源的释放问题就会出现下面的两种情况: 一开始获得的资源被绑定于局部对象 ...
- java.util.HashMap源码分析
在java jdk8中对HashMap的源码进行了优化,在jdk7中,HashMap处理“碰撞”的时候,都是采用链表来存储,当碰撞的结点很多时,查询时间是O(n). 在jdk8中,HashMap处理“ ...
- PL/SQL学习(四)存储过程和函数
原文参考:http://plsql-tutorial.com/ PL/SQL存储过程 存储过程相当于一个有名字的PL/SQL块,经过第一次编译后再次调用时不需要再次编译 创建格式: CREATE [O ...
- css实现的透明三角形
css实现下图样式,具体像素值记不住了,很好设置,html code (2014百度秋招面试题): <div id="demo"></div> 分析:这 ...
- curl采集 根据关键词 获取雅虎竞价排名
之前写过curl批处理采集数据,这里贴上完整版本,代码很简单,废话不说,上代码,新手欢迎指教!!! 代码只写到 获取到链接了,至于排名 后边数组的键不就是排名喽... <?php /** * B ...
- jinja2 宏的简单使用总结(macro)
Table of Contents 1. 简介 2. 用法 3. 参数和变量 4. 注意事项 4.1. macro的变量只能为如下三种: 4.2. 和block的关系: 5. 参考文档 1 简介 ji ...
- Python里隐藏的 " 诗 "
在 Python 的Lib目录里有一个:this.Py (或者在交互式解释器中输入import this) 它其实是隐藏的一首诗 The Zen of Python, by Tim Peters &l ...
- NotePad++更改背景颜色
白色的编辑框看得眼睛不舒服,怎么样更改NotePad++的背景颜色使眼睛更舒服些? 1.设置--语言格式设置 2.设置背景色 “背景色”一栏,选择背景色颜色 “使用全局背景色”一栏要打上√,否则无 ...