标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 35053 Accepted Submission(s): 13880
题目链接:HDU 1257
不明觉厉的新定理,定理内容参考这篇博客:http://www.cppblog.com/jie414341055/archive/2010/05/28/116632.html,这个定理大部分情况下可以用贪心搞搞代替
但是有了这个定理解法会更高大上一点= =|||,求个最长严格上升子序列长度即可
链的最少划分数=反链的最长长度
代码:
#include<stdio.h> #include<bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f #define CLR(x,y) memset(x,y,sizeof(x)) #define LC(x) (x<<1) #define RC(x) ((x<<1)+1) #define MID(x,y) ((x+y)>>1) typedef pair<int,int> pii; typedef long long LL; const double PI=acos(-1.0); const int N=100010; int arr[N],d[N]; void init() { CLR(arr,0); CLR(d,0); } int main(void) { int n,i,j; while (~scanf("%d",&n)) { for (i=1; i<=n; ++i) scanf("%d",&arr[i]); int len=1; d[len]=arr[len]; for (i=2; i<=n; ++i) { if(d[len]<arr[i]) d[++len]=arr[i]; else { int pos=lower_bound(d,d+len,arr[i])-d; d[pos]=arr[i]; } } printf("%d\n",len); init(); } return 0; }
HDU 1257 最少拦截系统(Dilworth定理+LIS)
标签:
原文地址:http://www.cnblogs.com/Blackops/p/5853923.html