hdu1160 FatMouse's Speed(LIS普通法)
来源:互联网 发布:cad自学软件 编辑:程序博客网 时间:2024/05/17 08:17
先以重量升序速度降序排序,求速度的LCS,LCS用路径表示,所以不能用二分法。。。今天才想起我不会普通法。。。 = =学习了。
唯一搞不懂的是为何样例不一样也还是能通过?
#include <stdio.h>#include <string.h>#include <algorithm>#include <vector>using namespace std;const int N = 1005;const int INF = 1000000;int n, dp[N], pre[N];struct MICE{ int w, s; int id;}mice[N];vector <int> mlen;bool cmp(MICE x, MICE y){ if(x.w == y.w) return x.s > y.s; else return x.w < y.w;}int main(){ // freopen("in.txt", "r", stdin); int i, j, k, maxl, idm; n = 0; while(~scanf("%d%d", &mice[n].w, &mice[n].s)) { mice[n].id = n + 1; dp[n] = 1; pre[n] = 0; n ++; } maxl = -1; mlen.clear(); sort(mice, mice + n, cmp); for(i = 1; i < n; i ++) for(j = 0; j < i; j ++) { if(mice[j].w < mice[i].w && mice[j].s > mice[i].s && dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; pre[i] = j; if(dp[i] > maxl) { maxl = dp[i]; idm = i; //最长子序列下标 } } } int x = dp[idm]; printf("%d\n", dp[idm]); while(idm) { mlen.push_back(idm); idm = pre[idm]; } for(i = x - 1; i >= 0; i --) printf("%d\n", mice[mlen[i]].id); return 0;}
0 0
- hdu1160 FatMouse's Speed(LIS普通法)
- HDU1160 FatMouse's Speed LIS变种+路径
- HDU1160--FatMouse's Speed
- HDU1160 FatMouse's Speed
- HDU1160 FatMouse's Speed
- hdu1160,FatMouse's Speed
- HDU1160--FatMouse's Speed
- hdu1160 FatMouse's Speed
- HDU1160 FatMouse's Speed
- hdu1160 FatMouse's Speed
- HDU1160 FatMouse's Speed
- hdu1160 FatMouse's Speed
- [HDU1160]-FatMouse's Speed
- hdu1160 FatMouse's Speed
- hdu1160 FatMouse's Speed 最长上升子序列 LIS
- HDU1160 FatMouse's Speed(DP,最长下降子序列)
- hdu1160 FatMouse's Speed (dp,记录路径)
- HDU1160 FatMouse's Speed(DP+路径记录)
- list类
- Android开发-WIFI实现
- LinearLayout中TextView基准线问题
- static class 静态类(Java)http://blog.sina.com.cn/s/blog_605f5b4f0100zbps.html
- poj2559栈应用
- hdu1160 FatMouse's Speed(LIS普通法)
- JavaSE入门学习24:Java面向对象补充
- 黑马程序员-OC加强-Block
- 图解Spark Transformation算子
- processing 鼠标光标显隐设置
- ubuntu再装软件是遇到 ubuntu-E:Encountered a section with no Package: header的解决办法
- 关于子网掩码(Netmask)
- 第10课:底实战详解使用Java开发Spark程序学习笔记
- php laravel mysql无法连接处理方案(linux服务器配置)