HDU 1160 FatMouse's Speed
2016-01-22 21:57
429 查看
题目链接:[kuangbin带你飞]专题十二 基础DP1 J - FatMouse’s Speed
dp[i] = max(dp[j]+1) 0<=j<=i-1
题意
给n个老鼠的体重和速度,求找出一个最长的序列,此序列体重递增速度递减思路
按体重递增排序,再求最长递增(此递增表示体重递增速度递减)子序列。dp[i] = max(dp[j]+1) 0<=j<=i-1
代码
[code]#include<iostream> #include<cstring> #include<cmath> #include<cstdio> #include<algorithm> #include<stack> #include<queue> using namespace std; const int N = 1006; struct Node { int a, b, i; bool operator <(const Node &t) const { return a < t.a; } }p ; int dp , fa , ans ; int main() { int pos = 0; while(~scanf("%d%d", &p[pos].a, &p[pos].b)) { p[pos].i = pos+1; pos++; } sort(p, p+pos); memset(fa, -1, sizeof(fa)); int ians = 0, amax = 0; for(int i=0; i<pos; i++) { int mmax = 0; for(int j=0; j<i; j++) { if(p[j].a < p[i].a && p[j].b > p[i].b && mmax < dp[j]) { mmax = dp[j]; fa[i] = j; } } dp[i] = mmax+1; if(amax < dp[i]) { amax = dp[i]; ians = i; } } printf("%d\n", amax); int i = 0; while(i < amax) { ans[i++] = p[ians].i; ians = fa[ians]; } while(i--) printf("%d\n", ans[i]); return 0; }
相关文章推荐
- 61. Implement Stack using Queues
- windows 32/64位系统 VS2010调用MATLAB2012生成的dll方法
- tcp粘包和拆包、断包
- 团队开发
- x265-1.7版本-common/frame.cpp注释
- 日本人为什么不吃鲤鱼
- 运维从业人员的危机
- [神经网络]1.3-Using neural nets to recognize handwritten digits-The architecture of neural networks(翻译)
- 外观模式
- 查找单词个数
- NGUI Button禁用(isEnabled和SetState区别)
- libRTMP使用说明
- x265-1.7版本-common/cudata.h注释
- leetcode 62. Unique Paths
- Spark sc.textFile(...).map(...).count() 执行完整流程
- Flume(3)source组件之NetcatSource使用介绍
- 【译文】Local Intensity Order Pattern for Feature Description
- 欢迎使用CSDN-markdown编辑器
- 解决 Android 编译报错:Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
- 电容并联