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 ...
随机推荐
- UIPanGestureRecognizer的使用
UIGestureRecognizer是一个定义基本手势的抽象类,具体什么手势,在以下子类中包含: 1.拍击UITapGestureRecognizer (任意次数的拍击) 2.向里或向外捏 ...
- DAG模型——嵌套矩阵
有向无环图上的动态规划是学习动态规划的基础,很多问题都可以转化为DAG上的最长路.最短路或路径计数问题. 嵌套矩阵 有n个矩阵,每个矩阵可以用两个整数a,b描述,表示它的长和宽.矩阵X(a,b)可以嵌 ...
- vim 自動化配置
Vim是Linux系統上常用的編輯器/Text Editor.不過很多人由於不瞭解如何配置,增加了很多煩惱. 今天介紹一個自動化的配置spf13,直接下載製作好的配置並進行自動設置. 1.官方的安裝步 ...
- Codevs 1814 最长链
1814 最长链 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 现给出一棵N个结点二叉树,问这棵二叉树中最长链的长度为多少, ...
- C++中string类型对象和double型变量之间的互相转换
//convert string type value to double type value string s = "23"; double d; istringstream ...
- Java面向对象程序设计--与C++对比说明:系列3(Java 继承机制)
继承(inheritance)背后的核心思想是: bonus = b; } } Java没有像C++那样提供多继承机制,但提供了接口机制,在后面我们将详细探究接口机制的实现 ...
- 专题一、ArrayList增删操作技术细节详解
一.索引检查 1)在指定位置插入元素时,第一步都需要检查输入的指定位置是否合法 public void add(int index, E element){ rangeCheckForAdd(i ...
- ubuntu 12.04 mysql转移目录后 无法 启动
http://www.boyunjian.com/do/article/snapshot.do?uid=com.iteye.xgbjmxn%2Fblog%2F1208086(转,) 我是用ap ...
- 『奇葩问题集锦』Ruby 切换淘宝源报错WARNING: Error fetching data: SSL_connect returned=1 errno=0 state=SSLv3 read s erver certificate B: certificate verify failed
===>首先需要使用https<===https://ruby.taobao.org/ 第一步 下载http://pan.baidu.com/s/1kU0rxtH 复制到ruby安装的根目 ...
- PHP - 传入WebService服务端带中文字符的序列化字串不能反序列化的解决方法
因工作需要,用了web服务,通过远程调用的方式来检索雅虎拍卖数据.前几天遇到一个问题,现在记录一下 客户端: $res = $this->client->call('Get_YahooDa ...