传送门:

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. Log4Net 用法记录

    https://www.cnblogs.com/lzrabbit/archive/2012/03/23/2413180.html https://blog.csdn.net/guyswj/articl ...

  2. [lougu1341]无序字母对

    Description: 给定n个各不相同的无序字母对(区分大小写,无序即字母对中的两个字母可以位置颠倒).请构造一个有n+1个字母的字符串使得每个字母对都在这个字符串中出现. Solution: 欧 ...

  3. 使用spring-boot 国际化配置所碰到的乱码问题

    写好html静态页面 ,  也加上了编码格式 , 获取国际化展示在浏览器中还是存在乱码 , 开始以为是浏览器编码格式问题 , 做过处理后任没有得到解决 , 具体的处理方案如下: <meta ht ...

  4. 运行 CMD 时,參数加引號常见问题

    在调用 CMD 时.如脚本中用 WScript.Shell 调用. 假设參数中有包括空格的长路径名时,必需要加引號才干正确被识别. 是的,大家都知道要加引號.但怎么加却easy被误解.这个问题,不时地 ...

  5. 关于使用strtok的一个小问题

    今天在弄一下啊小小程序的时候.报错,出现了问题.先看代码 int main(int argc, char* argv[]) { char *filename = "interface_ips ...

  6. Ajax跨域:Jsonp实例--百度搜索框下拉提示

    Ajax跨域:Jsonp实例--百度搜索框下拉提示 一.总结 一句话总结:a.找好接口:b.用script标签的src引入文件(json数据):c.定义及实现上一步引入文件中的函数 1.如何找到一个网 ...

  7. Unix下后门查找{上}

    本文出自 "李晨光原创技术博客" 博客,请务必保留此出处http://chenguang.blog.51cto.com/350944/683699

  8. 微信小程序简单常见首页demo

    wxml <view class='index-contier'> <view class="index-left"> <view>电池剩余&l ...

  9. [Vue + TS] Using Route events inside Vue

    vue-router introduces new hooks into the component. In this lesson we’ll show you how to use these n ...

  10. Lamp(linux+apache+mysql+php)环境搭建

    Lamp(linux+apache+mysql+php)环境搭建 .安装apache2:sudo apt-get installapache2 安装完毕后.执行例如以下命令重新启动apache:sud ...