PAT L2-014 列车调度(Dilworth定理)
来源:互联网 发布:js获取style属性 编辑:程序博客网 时间:2024/05/16 10:12
分析
比赛的时候一直在贪心做来着,一直WA。
卧槽,原来是一个定理啊。
Dilworth定理 还不懂的戳这里;
总之就是一句话,最长反链长==偏序链的划分数、
这里的偏序链为递减的,那就是要求 最长递增子序列的长度了;
再一看数据范围挺大的,得用nlogn的那种解法了:
AC代码:
#include <iostream>#include <cmath>#include <cstring>typedef long long ll;typedef unsigned long long ull;using namespace std;const int maxn = 1e5 + 100;const int inf = 999999999;int dp[maxn], a[maxn];int main(){#ifdef LOCAL //freopen("L2-014(Dilworth).in","r",stdin); //freopen("L2-014(Dilworth).out","w",stdout);#endif int n; while(cin >> n) { int len = 0; memset(dp, 0, sizeof(dp)); for(int i = 0; i < n; i++) { int x; cin >> x; if(len == 0 || x >= dp[len-1]) dp[len++] = x; else { int l = 0, r = len - 1; while(l <= r) { int mid = (l+r)/2; if(dp[mid] <= x) l = mid+1; else r = mid - 1; } dp[l] = min(dp[l], x); } } cout << len << endl; } return 0;}
0 0
- 【PAT L2-014】列车调度(Dilworth定理)
- PAT L2-014 列车调度(Dilworth定理)
- pta L2-014. 列车调度 Dilworth定理(最少下降子序列数等于最长上升子序列长度)@
- PAT-L2-014. 列车调度
- PAT:L2-014. 列车调度
- L2-014 列车调度
- 列车调度(PAT)
- L2-014. 列车调度
- L2-014. 列车调度
- L2-014. 列车调度
- L2-014. 列车调度
- L2-014. 列车调度
- L2-014. 列车调度
- L2-014. 列车调度
- L2-014. 列车调度
- L2-014. 列车调度
- L2-014. 列车调度
- L2-014. 列车调度
- String,StringBuffer与StringBuilder的区别?
- hdoj5835【水题】
- Servlet的细节和线程安全
- HDU 1397 Goldbach's Conjecture
- 微信那些事儿(一)
- PAT L2-014 列车调度(Dilworth定理)
- scala进阶9-链式操作内幕
- 这个世界有真爱吗
- CString、TCHAR*、char*转换
- c/c++
- 数据库中间件Mycat源码解析(一):初识Mycat
- HTTP协议②
- Windows系统概述
- Android之科普APP框架