FatMouse's Speed---hdu1160(简单dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160
题意就是给你一些老鼠(编号1,2,3,4,5,6,7,8...)的体重和他们的速度然后求出最大的n满足
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[n]]
然后把原来的编号按照上面的序列输出来;
先把他们排序一下dp的时候记录一下路径;
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define N 1550
#define INF 0xffffff
struct node
{
int w, s, id;
}a[N];
int cmp(node p, node q)
{
if(p.w!=q.w)
return p.w<q.w;
return p.s>q.s;
}
int main()
{
int n=, dp[N], pre[N];
///freopen("in.txt", "r", stdin);
while(scanf("%d%d", &a[n].w, &a[n].s)!=EOF)
{
a[n].id=n+;
n++;
}
sort(a, a+n, cmp);
memset(dp, , sizeof(dp));
memset(pre, -, sizeof(pre));
int Max = ;
int Index = -;
for(int i=; i<n; i++)
{
dp[i]=;
for(int j=; j<i; j++)
{
if(a[j].w<a[i].w && a[j].s>a[i].s)
{
if(dp[j]+>dp[i])
{
dp[i]=dp[j]+;
pre[i]=j;
}
}
}
if(Max<dp[i])
{
Max = dp[i];
Index = i;
}
}
printf("%d\n", Max);
int b[N]={},k=;
for(int i=Index; i!=-; i=pre[i])
{
b[k++]=a[i].id;
}
for(int i=k-; i>=; i--)
printf("%d\n", b[i]);
return ;
}
FatMouse's Speed---hdu1160(简单dp)的更多相关文章
- hdu1160简单dp最长下降子序列
/* 简单dp,要记录顺序 解:先排序,然后是一个最长下降子序列 ,中间需记录顺序 dp[i]=Max(dp[i],dp[j]+1); */ #include<stdio.h> #incl ...
- FatMouse's Speed ~(基础DP)打印路径的上升子序列
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take ...
- 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 ...
- HDU1160 FatMouse's Speed —— DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS ...
- HDU 1160 FatMouse's Speed (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- 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 基础dp
FatMouse's Speed Time Limit: 2 Seconds Memory Limit:65536 KB Special Judge FatMouse believe ...
- zoj 1108 FatMouse's Speed 基础dp
FatMouse's Speed Time Limit: 2 Seconds Memory Limit:65536 KB Special Judge FatMouse believe ...
- FatMouse's Speed
J - FatMouse's Speed DP的题写得多了慢慢也有了思路,虽然也还只是很简单的DP. 因为需要输出所有选择的老鼠,所以刚开始的时候想利用状态压缩来储存所选择的老鼠,后面才发现n太大1& ...
随机推荐
- sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛
Mountain Subsequences 题目描述 Coco is a beautiful ACMer girl living in a very beautiful mountain. There ...
- linux之grub的使用
一.引言 昨天在家里在自己的电脑上安装CentOS7,一切都顺利,结果安装好重启,无法进入win7了,在grub的配置文件也添加了win7的条目,却提示 unkown command chainloa ...
- CentOS6.2下安装中文输入法
因为在程序中需要输入中文,但是系统没有预装中文输入法,所以就安装一下,顺便记录 1.用root登录 ,或su root2.yum install "@Chinese Support" ...
- 安全DNS
国内首家云安全DNS:(114DNS)114.114.114.114114.114.115.115 将 DNS 地址设为114.114.114.119 和 114.114.115.119 ,拦截钓鱼病 ...
- 【未完成】junit简单使用
参考资料: 一般使用:https://www.w3cschool.cn/junit/ 集成spring: https://www.cnblogs.com/faramita2016/p/7637086. ...
- The Definitive Guide To Django 2 学习笔记(七) 第四章 模板 (三)使用模板系统
接下来,我们开始学习如何使用模板系统,但我们并不和前面说的View相结合,我们的这里的目的是展示模板系统是如何独立于Django框架运行的.下面是在pyhon代码中使用Django模板系统的基础例子: ...
- The Boss on Mars
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- web中用纯CSS实现筛选菜单
web中用纯CSS实现筛选菜单 本文我们来用纯css实现像淘宝宝贝筛选菜单那样的效果,例子虽然没有淘宝那样强大,不过原理差不多,如果花点心思也可以实现和淘宝一样的. 内容过滤是一个在Web上常见的一个 ...
- mfc小工具开发之定时闹钟之---时间获取和音频播放
1.这里的音频文件是指*.wav格式的音频,参考了飞雪的音频文件,版本号: 飞雪桌面日历 v2.84.1025 绿色版 http://www.piaodown.com/down/soft/18512. ...
- js节流防抖应用场景,以及在vue中节流防抖的具体实现
故事背景: 项目有个需求是输入框在输入的时候进行搜索,展示下拉数据,但是没必要输入一个字都进行搜索,所以想到了在输入结束200毫秒后再进行搜索,从而引出来了 js的节流(throttle),防抖(de ...