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 ...
随机推荐
- iOS NSNumber语法糖
BOOL equal; NSNumber * num1 = [NSNumber numberWithInteger:]; NSNumber * num2 = @; equal = [num1 isEq ...
- javax.el.PropertyNotFoundException: Property 'aDesc' not found on type
这个问题是是在我使用jeesite自动代码是产生的,原因是实体类的属性命名规范不合格,我在网上看到类的属性前三个字母不能出现大写 解决办法:将类的属性大小写改一下
- 【POJ2094】【差分序列】Angry Teacher
Description Mr. O'Cruel is teaching Math to ninth grade students. Students of course are very lazy, ...
- (转)C++设计模式——观察者模式
转自:http://www.jellythink.com/archives/359 前言 之前做了一个性能测试的项目,就是需要对现在的产品进行性能测试,获得测试数据,然后书写测试报告,并提出合理化的改 ...
- ASP.NET中的特殊路径标识"~"
/ 表示网站根目录(从域名开始), ../ 表示上级目录, ./表示当前目录- 是ASP.NET定义的特殊符号,是ASP.NET内部进行定义推荐的用法,-代表从应用根目录开始定义应用根目录与网站根目录 ...
- 网站开发常用jQuery插件总结(七)背景插件backstretch
一.backstretch插件功能 优化网站外观.主要用于设置页面背景图片,也可以设置html元素的背景图片.背景图片可以设置多张,在间隔时间内循环显示. 注 但是在设置背景图片时,如果图片过大,网站 ...
- php 验证码生成方法 及使用
基本思路是: 在生成图片的页面中(as: yzm.php)1.设置生成的图片的宽度和高度:2.设置图片要写入的字符:3.截取显示在图片上的字符;4.开启session,把上面截取的字符存放在sessi ...
- 如何判断list中是否包含某个元素
在python中可以通过in和not in关键字来判读一个list中是否包含一个元素: str = ['s','i','m','o','n'] if 'e' in str: print("e ...
- VMWare Workstation 占用443端口导致apache启动不了
中午安装vm,装linux 系统,搞了好几次才装成功,下午启动apache 忽然发现apache启动不了,各种郁闷啊,打开错误日志,NameVirtualHost无效,各种郁闷呐,试着修改端口,修改配 ...
- std::copy的使用
看到有人在用std::copy这个东西,很简洁和爽啊,,所以找些帖子学习学习 http://blog.sina.com.cn/s/blog_8655aeca0100t6qe.html https:// ...