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& ...
随机推荐
- 电脑不识别USB blaster驱动问题
电脑不识别USB blaster,如下图: 解决办法:手动更新 http://zhidao.baidu.com/link?url=snVT__AsbtmQ4U5EBVN05Yrgv1TPv7AdVYe ...
- Swift中UIView类方法(animateWithDuration)的使用
需求:利用Swift语言实现OC语言中UIView类方法 [UIView animateWithDuration:0.5 animations:^{ bgView.alpha= 1; }]; 在Swi ...
- 汉诺塔(-) java modPow 的用法;
汉诺塔(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 在印度,有这么一个古老的传说:在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针.印度教的 ...
- CCNA2.0笔记_安全管理设备
设备安全 配置Console密码 Switch(config)#line console 0 Switch(config-line)#login Switch(config-line)#passwor ...
- Objective-C中.h文件、.m文件中@interface、@synthesize及其它
很多开发iOS好几年的老鸟,可能都不太分的清.h文件和.m文件里各种结构的用途和区别.最近仔细研究了一下,写一篇文章记下来. 一般的,写一个Class的时候,经常是这种格式(以UIViewContro ...
- LeetCode 145 Binary Tree Postorder Traversal(二叉树的兴许遍历)+(二叉树、迭代)
翻译 给定一个二叉树.返回其兴许遍历的节点的值. 比如: 给定二叉树为 {1. #, 2, 3} 1 \ 2 / 3 返回 [3, 2, 1] 备注:用递归是微不足道的,你能够用迭代来完毕它吗? 原文 ...
- Mybatis热加载Mapper.xml
开发的时候,写Mybatis Mapper.xml文件的时候,每次修改SQL都需要重启服务,感觉十分麻烦,于是尝试写了一个Mybatis的Mapper.xml热加载. 能在修改Mapper.xml之后 ...
- traceroute/tracert--获取网络路由路径
traceroute 是用来检测发出数据包的主机到目标主机之间所经过的网关数量的工具.traceroute 的原理是试图以最小的TTL发出探测包来跟踪数据包到达目标主机所经过的网关,然后监听一个来自网 ...
- vim 将tab转为空格
在vimrc中添加以下选项 set expandtab 会将tab转换为空格,如果要输入一个tab则需要Ctrl-V<Tab>来实现 set tabstop= 会将tab转换为4个空格 使 ...
- 发送json-简单的传参查询和简单的sql查询
简单的传参查询并转化为json using System; using System.Collections.Generic; using System.Linq; using System.Web; ...