HDU 1160 FatMouse's Speed
2016-01-18 13:25
405 查看
简单DP,最长上升子序列。先对W排序,然后对S做做LIS
#include<cstdio> #include<cstring> #include<cmath> #include<stack> #include<vector> #include<algorithm> using namespace std; const int maxn=10000+10; struct X { int w,s; int id; } x[maxn]; bool cmp(const X&a,const X&b) { return a.w<b.w; } int pre[maxn],dp[maxn]; stack<int>S; int main() { int n=0; while(~scanf("%d %d",&x .w,&x .s)) { x[n++].id=n+1; } while(!S.empty())S.pop(); sort(x,x+n,cmp); memset(dp,1,sizeof dp); memset(pre,-1,sizeof pre); for(int i=0; i<n; i++) { int Max=0,Pos=-1; for(int j=0; j<i; j++) { if(x[j].w<x[i].w) { if(x[j].s>x[i].s) { if(dp[j]>Max) { Max=dp[j]; Pos=j; } } } } dp[i]=Max+1; pre[i]=Pos; } int ans=0,ansPos=-1; for(int i=0; i<n; i++) { if(dp[i]>ans) { ans=dp[i]; ansPos=i; } } int nowPos=ansPos; while(1) { S.push(nowPos); nowPos=pre[nowPos]; if(nowPos==-1) break; } printf("%d\n",ans); while(!S.empty()) { printf("%d\n",x[S.top()].id); S.pop(); } return 0; }
相关文章推荐
- 以这篇文章,结束我的前端职业
- 结合实例与代码谈数字图像处理都研究什么?
- LeetCode 263 Ugly Number
- 《1024伐木累》-小白篇之开发网站,三天!(前篇)-总章节八
- WCF存储图片到指定文件夹下
- JVM分析工具链(三) - jstat和hprof
- 读什么,一张清单让你知道为什么你读了很多书,却不如古人
- java入门学习(8)—类成员及单例类
- ios基本控件之UIControl
- 排序算法之直接插入排序
- mybatis查询有关联关系并且有相同字段的两张表问题解决
- [Django](1093, "You can't specify target table 'fee_details_invoices' for update in FROM clause") 错误
- netbeans等宽字体却不支持中文
- 让一个label中的text显示不同的颜色,字体
- [JSOI2008]球形空间产生器 (高斯消元)
- 65条最常用正则表达式
- ios基本控件之UIButton
- Java并发编程实战学习笔记(三)-线程封闭
- 网页性能优化工具
- Android Studio 配置 androidAnnotations框架详细步骤