传送门:

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. HDU 2689 Tree

    Tree Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. 趣题: 按二进制中1的个数枚举1~2^n (位运算技巧)

    ; ; k <= n; k++){ << k)-,u = << n; s < u;){ ;i < n;i++) printf(-i)&); print ...

  3. 今日SGU 5.9

    SGU 297 题意:就是求余数 收获:无 #include<bits/stdc++.h> #define de(x) cout<<#x<<"=" ...

  4. java bigdecimal (java double也时会失真)

    BigDecimal加减乘除运算 2011-11-21 21:22 6470人阅读 评论(0) 收藏 举报 stringdivjavaup工具 java.math.BigDecimal.BigDeci ...

  5. HDOJ 5357 Easy Sequence DP

    a[i] 表示以i字符开头的合法序列有多少个 b[i] 表示以i字符结尾的合法序列有多少个 up表示上一层的'('的相应位置 mt[i] i匹配的相应位置 c[i] 包括i字符的合法序列个数  c[i ...

  6. POJ 3243 Clever Y Extended-Baby-Step-Giant-Step

    题目大意:给定A,B,C,求最小的非负整数x,使A^x==B(%C) 传说中的EXBSGS算法0.0 卡了一天没看懂 最后硬扒各大神犇的代码才略微弄懂点0.0 參考资料: http://quarter ...

  7. JAVASE学习笔记:第十章 SWing经常使用控件类(二)

    7.JComboBox 下拉列表         /*   * 初始化下拉列表   */  public void addcomb(){   String[] area = {"山西省&qu ...

  8. js插件---放大镜如何使用

    js插件---放大镜如何使用 一.总结 一句话总结:一张高清图片被用了两次,一次做缩略图,一次做放大后显示用的的图片(其实这个图片就是高清图片本身,而且是部分) 14 <figure class ...

  9. elasticsearch transport 请求发送和处理

    前一篇分析对nettytransport的启动及连接,本篇主要分析transport请求的发送和处理过程.cluster中各个节点之间需要相互发送很多信息,如master检测其它节点是否存在,node ...

  10. zookeeper 配置文件说明(zoo.cfg)

    clientPort      # 客户端连接server的port,即对外服务port,一般设置为2181. dataDir        # 存储快照文件snapshot的文件夹. 默认情况下.事 ...