FatMouse's Speed--hdu1160(dp+输出路径)
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.
题目大意:
这是个大英文题啊
他给你老鼠的体重和奔跑的速度
然后当体重呈升序的时候 速度的最长下降序列
这都不重要 重要的是还要打印路径
分析:
就是先对体重排序
然后求最长下降序列
再求的过程中记录路径 最后输出
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<stdlib.h> using namespace std; #define INF 0xfffffff
#define N 5000 struct node
{
int num,w,s;
}a[N]; int cmp(const void *x,const void *y)
{
struct node *c,*d;
c=(struct node *)x;
d=(struct node *)y;
if(c->w!=d->w)
return c->w-d->w;
else
return d->s-c->s;
}
int main()
{
int i=,pre[N],dp[N];
while(scanf("%d %d",&a[i].w,&a[i].s)!=EOF)
{
dp[i]=;
pre[i]=;
a[i].num=i+;
i++;
}
int n=i,b,Max=;
qsort(a,n,sizeof(a[]),cmp);
for(i=;i<n;i++)
{
for(int j=;j<i;j++)
{
if(a[j].w<a[i].w&&a[j].s>a[i].s&&dp[j]+>dp[i])
{
dp[i]=dp[j]+;
pre[i]=j;
if(Max<dp[i])
{
b=i;
Max=dp[i];
}
}
}
}
int aa[N];
printf("%d\n",Max);
aa[]=a[b].num;
i=;
while()
{
int j=pre[b];
if(j==)
break;
aa[i++]=a[j].num;
b=j;
}
for(int j=i-;j>=;j--)
printf("%d\n",aa[j]);
return ;
}
FatMouse's Speed--hdu1160(dp+输出路径)的更多相关文章
- zoj 1108 FatMouse's Speed 基础dp
FatMouse's Speed Time Limit: 2 Seconds Memory Limit:65536 KB Special Judge FatMouse believe ...
- HDU 1160:FatMouse's Speed(LIS+记录路径)
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 ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- FatMouse's Speed 基础DP
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1160 FatMouse's Speed ——(DP)
又是那个lis变形的题目. 但是不好定义严格的比较符号,因此只能n^2去做.值得注意的一个是要先排序,因为可能可以先选后面的再选前面的,先排序的话就能够避免这个问题.但是要注意,因为要输出路径,所以要 ...
- 机器分配——线性dp输出路径
题目描述 总公司拥有高效设备M台, 准备分给下属的N个分公司.各分公司若获得这些设备,可以为国家提供一定的盈利.问:如何分配这M台设备才能使国家得到的盈利最大?求出最大盈利值.其中M <= 15 ...
- HDU 1160 FatMouse's Speed(DP)
点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...
- Codeforces Round #436 E. Fire(背包dp+输出路径)
题意:失火了,有n个物品,每个物品有价值pi,必须在时间di前(小于di)被救,否则就要被烧毁.救某个物 品需要时间ti,问最多救回多少价值的物品,并输出救物品的顺序. Examples Input ...
随机推荐
- Docker - Image创建
自己创建Image会有一些好处,可以选择最新的版本,而且从国内的镜像创建时更新软件也会从该镜像获取,速度更快. (1)安装debootstrap zhouh1@uhome:/media/zhouh1/ ...
- 手写MVVM框架 之vue双向数据绑定原理剖析
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- php用面向对象从mysql取数据
<?php //建立数据库的链接@$_mysqli = new mysqli('localhost','root','123456','dbname');if(mysqli_connect_er ...
- QT+信号和槽函数_自定义槽函数_一个信号对应多个槽函数
以下的代码里面有自定义槽函数的内容,同时也有信号实现的函数: #ifndef MAINWIDGET_H #define MAINWIDGET_H #include <QWidget> #i ...
- JavaSE-31 Java正则表达式
概述 正则表达式是一个强大的字符串处理工具,可以实现对字符串的查找.提取.分割.替换等操作. String类的几个方法需要依赖正则表达式的支持. 方法 方法说明 boolean matches(Str ...
- Java之字符,字符串替换
/** 4. 字符串的替换操作 1. String replace(char oldChar,char newChar) //将新字符替换旧字符 3. String replaceFirst(Stri ...
- Java中的BIO,NIO,AIO分别是什么
BIO:同步并阻塞,服务器实现模式为一个连接一个线程,即客户端有连接请求时服务器端就需要启动一个线程进行处理,如果这个连接不做任何事情会造成不必要的线程开销,当然可以通过线程池机制改善.BIO方式适用 ...
- 任务备忘(已经完成):用python写一个格式化xml字符串的程序
功能: 1.将xml中多余的空格,换行符去掉,让xml字符串变成一行. 2.将xml中添加缩进,使用print能正确打印添加缩进后的字符串. 思路: 采用正则表达式来判断xml中字符串的类型: 1.文 ...
- 用python的Requests库模拟http请求
一.先了解几个重要的http请求头或响应头信息 Request Headers: Host: 描述请求将被发送的目的地,包括,且仅仅包括域名和端口号. Origin: 说明请求从哪里发起的,包括,且仅 ...
- [Android]使用button切换TextView可见和不可见
<Button android:id="@+id/btnTest" android:layout_width="match_parent" android ...