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/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的更多相关文章
- 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 -- hdu -- 1160
http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/Other ...
- FatMouse's Speed HDU - 1160 最长上升序列, 线性DP
#include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> usi ...
- HDU 1160 DP最长子序列
G - FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- FatMouse's Speed ~(基础DP)打印路径的上升子序列
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take ...
- ZOJ 2109 FatMouse' Trade (背包 dp + 贪婪)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1109 FatMouse prepared M pounds of cat ...
- FatMouse and Cheese HDU - 1078 dp
#include<cstdio> #include<iostream> #include<cstring> using namespace std; int n,k ...
- HDU 1160 FatMouse's Speed (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
随机推荐
- spark源码阅读
根据spark2.2的编译顺序来确定源码阅读顺序,只阅读核心的基本部分. 1.common目录 ①Tags②Sketch③Networking④Shuffle Streaming Service⑤Un ...
- vue prpos
匹配某些值中的一个 type: { validator: function(value) { return ["success", "warning", &qu ...
- Android程序使用SOAP调用远程WebService服务
在现在的应用程序中.不可能不使用到网络,而且后台一定是有server作为支撑的. 现在最常见的调用方式有HTTP的GET .POST方式,返回JSON或者XML数据. 可是也有一种常见的形式就是调用W ...
- jQuery03
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- php函数按地址传递参数(php引用)
php函数按地址传递参数(php引用) 一.总结 1.php引用:php引用和c++一样,都是在变量前加&(取地址符号) 2.php函数按地址传递参数:php函数按地址传递参数(php引用)也 ...
- popover弹出框
<style> #view{width: 300px;height: 200px;border: 1px solid red;} </style> 以上是为了viewport更 ...
- 暴力破解FTP服务器技术探讨与防范措施
暴力破解FTP服务器技术探讨与防范措施 随着Internet的发展出现了由于大量傻瓜化黑客工具任何一种黑客攻击手段的门槛都降低了很多但是暴力破解法的工具制作都已经非常容易大家通常会认为暴力破解攻击只是 ...
- golang 方法内部定义子方法及调用
package main import ( "fmt" "reflect" ) func out(ch chan int) { <-ch fmt.Prin ...
- Spring源码分析专题 —— 阅读指引
阅读源码的意义 更深入理解框架原理,印象更深刻 学习优秀的编程风格.编程技巧.设计思想 解决实际问题,如修复框架中的bug,或是参考框架源码,结合实际业务需求编写一个独有的框架 阅读源码的方法 首先是 ...
- [转]Accept-Encoding
原文地址:https://blog.csdn.net/sqzhao/article/details/49499471 HTTP Header中Accept-Encoding 是浏览器发给服务器,声明浏 ...