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 ...
随机推荐
- stm32中.bss和.data段是在哪里初始化的
https://segmentfault.com/q/1010000004829859/a-1020000004850311 Q: STM32的启动文件startup_stm32f10x_hd.s中的 ...
- (转)所有iOS设备的屏幕分辨率
Phone: iPhone 1G 320x480 iPhone 3G 320x480 iPhone 3GS 320x480 iPhone 640x960 iPhone 4S 640x960 iPhon ...
- WebConfig加密解密
加密:aspnet_regiis -pef appSettings "G:\FlyMusicNew\Web"解密:aspnet_regiis -pdf appSettings &q ...
- 《APUE》第三章笔记(2)
read函数 调用read函数从打开的文件中读数据. #include <unistd.h> ssize_t read(int filedes, void *buf, size_t nby ...
- tmux复制到windows剪贴板/粘贴板的坑
以下所有操作都是在windows下面用putty连接linux centos6的情景下. 一直很纳闷为什么在tmux模式下不能把复制到的文字放到系统的粘贴板里面呢?通过层层阻碍,终于找到了原因. 去掉 ...
- 列表字体css
white-space: nowrap; text-overflow: ellipsis; -o-text-overflow: ellipsis; overflow: hidden;
- 几个 JavaScript 奇技淫巧
#1使用双等号给布尔变量赋值,很容易联想到 var a = b || 123; 的写法 var a = b == 123;#2快速转换为布尔值 !!a#3防止页面被 iframe 调用 if(top ...
- jquery实现抽奖
用jquery实现抽奖小程序 用jquery实现抽奖小程序 这些日子,到处都可以看到关于微信小程序的新闻或报到,在博客园中写关于微信小程序的也不少.但是今天我要说的不是微信小程序,而是用简单的jq ...
- Clang 与 LLVM
我们在iOS调试中经常会看到Clang这个,那么Clang到底是什么呢?我们来简单了解一下. Clang是一个C.C++.OC语言的轻量级编译器.源代码发布于BSD协议下.Clang是由C++编写,基 ...
- python学习之--内置函数:
Python内置函数: Python内置了很多有用的函数,我们可以直接调用.要调用一个函数,需要知道函数的名称和参数,比如求绝对值的函数abs,只有一个参数. 1. 内置函数调用之--abs()函数: ...