传送门:

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. sparksql不支持hive中的分区名称大写

    但是在hive中查询是可以的. 后来经过一点一点测试发现,原来分区名称不能是大写,必须小写才行.

  2. Spring boot 解析jsp支持jsp热部署

    解析jsp并且支持jsp热部署 参考地址:https://www.wanpishe.top/detail?blogId=39875536-7d45-48ec-a7b5-f36b85c3a235

  3. WPF通用框架 数据库结构

    前言 由於技術轉型, 目前大部分工作都是WPF為主, 但是趨於如今想在網絡上找一套能夠滿意的WPF權限管理框架太難, 因為WinForm那時候是有一套改寫過的權限框架, 所以數據庫設計這塊已經有了一個 ...

  4. Cocos2d-x 之大牛看法

    (未完毕) cocos2d-x并非一个适合网游client(mmo)的游戏引擎.越是大型游戏,这个小引擎就越无法驾驭(尽管它很受欢迎). 之前我在原来的公司使用的是自主研发的C3引擎,已经对外开放(尚 ...

  5. QTemporaryDir及QTemporaryFile建立临时目录及文件夹(创建一个随机名称的目录或文件,两者均能保证不会覆盖已有文件)

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址:本文标题:QTemporaryDir及QTemporaryFile建立临时目录及文件夹     本文地址: ...

  6. js28--适配器模式

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  7. 企业部署Linux应用将拥有更低的TCO

    650) this.width=650;" onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" ...

  8. http 500 Internal Server Error的错误 ajax请求SpringMVC后台中返回500 Internal Server Error

    使用httprequester接口测试能返回数据,但是用ajax返回json格式的时候返回报500Internal Server Error. The server encountered an in ...

  9. springMVC通过ajax传递参数list对象或传递数组对象到后台

    springMVC通过ajax传递参数list对象或传递数组对象到后台 环境: 前台传递参数到后台 前台使用ajax 后台使用springMVC 传递的参数是N多个对象 JSON对象和JSON字符串 ...

  10. Writing buffer overflow exploits - a tutorial for beginners

    Buffer overflows in user input dependent buffers have become one of the biggest security hazards on ...