传送门:

ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=108

HDU :http://acm.hdu.edu.cn/showproblem.php?pid=1160

题目大意:

输入好多组w 和 s 代表老鼠的重量和速度,要求找出满足 w 严格 升序, s严格降序的最大长度和他们的序号。

我是先排序,然后和ZOJ 1136 Longest Ordered Subsequence (http://blog.csdn.net/murmured/article/details/14646445)一样。设dp [ i] 为 以 i 结尾的升序列的最大值,那么从 i 开始向前查找,若 a[ j ]
< a [ i ] 则 比较一下 dp的大小。

同时要存下序列。

虽然和题目的样例输出不一样,但这是正确的,因为解不唯一。题目也只要求一组解。

分析如图:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct mouse
{
int id;
int weight;
int speed;
}m[1024];
int dp[1024];
int data[1024][1024];
bool operator < (const mouse &a,const mouse &b)
{
return a.weight < b.weight;
} int main()
{
int w,s,len=1;
while(~scanf("%d%d",&w,&s))
{
m[len].id=len;
m[len].weight=w;
m[len].speed=s;
len++;
} sort(m,m+len); dp[1]=1;
data[1][1]= m[1].id;
for(int i=2;i<len;i++)
{
int temp=0;
int index=i;
for(int j=i-1;j>=1;j--)
{
if( m[j].speed > m[i].speed && m[i].weight!=m[j].weight)
{
if(temp < dp[j])
{
temp=dp[j];
index=j;
}
}
} dp[i]=temp+1;
if(index!=i)
{
memcpy(data[i],data[index],sizeof(data[index]) );
data[ i ][ dp[i] ] = m[i].id;
}
else
data[i][1]= m[i].id;
} int ans=0,index=1;
for(int i=1;i<len;i++)
{
if(ans< dp[i])
{
ans= dp[i] ;
index= i;
}
} printf("%d\n",ans);
for(int i=1;i<=ans;i++)
{
printf("%d\n",data[index][i]);
}
return 0;
}

ZOJ 1108 FatMouse's Speed (HDU 1160) DP的更多相关文章

  1. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  2. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  3. (最长上升子序列 并记录过程)FatMouse's Speed -- hdu -- 1160

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/Other ...

  4. FatMouse's Speed HDU - 1160 最长上升序列, 线性DP

    #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> usi ...

  5. HDU 1160 DP最长子序列

    G - FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  6. FatMouse's Speed ~(基础DP)打印路径的上升子序列

    FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take ...

  7. ZOJ 2109 FatMouse&#39; Trade (背包 dp + 贪婪)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1109 FatMouse prepared M pounds of cat ...

  8. FatMouse and Cheese HDU - 1078 dp

    #include<cstdio> #include<iostream> #include<cstring> using namespace std; int n,k ...

  9. HDU 1160 FatMouse's Speed (DP)

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

随机推荐

  1. Dubbo简易学习

    0.  Dubbo简易介绍 DUBBO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000, ...

  2. VMware Vsphere 6.0安装部署 总体部署架构

    (一)总体部署架构 本教程用于学习目的,力求详尽的介绍安装部署过程和各组件之间的关系,部署过程从最简单的模型开始,系列文章按时间顺序依次展开,每篇介绍一个组件. 开始阶段,按照一台物理服务器,部署所有 ...

  3. GestureDetector- 滑屏手势方式实现

    今天做的项目中,需要使用滑屏来调出一个界面,经过自己的尝试,结合网上的方法,成功实现了. 代码如下 package com.example.text; import android.app.Activ ...

  4. WPF 入门《布局面板》

    常见的几个布局面板 1.StackPanel面板 StackPanel面板能够简单根据单行或者单列进行元素排列, StackPanel 默认的布局方向为垂直方向(Vertical), 由Orienta ...

  5. ZOJ 题目3587 Marlon&#39;s String(KMP)

    Marlon's String Time Limit: 2 Seconds      Memory Limit: 65536 KB Long long ago, there was a coder n ...

  6. Android时间对话框TimePickerDialog介绍

    目前网上流行着很多对“时间对话框TimePickerDialog”的讲解文章,但感觉都不是很详细.这里详细对该方面的知识进行介绍,旨在帮助初学者能够快速掌握该项技术. 首先要做的是声明一个日历类的对象 ...

  7. JS contcat() 连接数组 函数

    语法: arrayObject.concat(arrayX,arrayX,......,arrayX) 1.把元素添加到数组中 arr.concat(a,b,c);2.把数组连起来 arr.conca ...

  8. scrapy--介绍

    ​ Scrapy一个开源和协作的框架,其最初是为了页面抓取所设计的,使用它可以以快速.简单.可扩展的方式从网站中提取所需的数据.但目前Scrapy的用途十分广泛,可用于如数据挖掘.监测和自动化测试等领 ...

  9. [UWP]为什么ContentControl的ContentTemplate里放两个ContentPresenter会出问题(绕口)

    原文:[UWP]为什么ContentControl的ContentTemplate里放两个ContentPresenter会出问题(绕口) 1. 简单的HeaderedContentControl 上 ...

  10. ActiveX控件开发 C#

    转自:http://hi.baidu.com/charlesx_kst/item/9c2f42e2920db3f42b09a4ff 前言: 这段时间因为工作的需要,研究了一下ActiveX控件.总结如 ...