标签:algo 帮助 esc targe comm scan sele min col
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 58581 Accepted Submission(s): 23023
#include <iostream> #include <cstdio> #include <algorithm> #define inf 0x3f3f3f3f #define MAX 100000 using namespace std; int n; int s[MAX]; int main() { int d; while(~scanf("%d",&n)) { int c = 0; for(int i = 0;i < n;i ++) { scanf("%d",&d); if(d > s[c]) { s[++ c] = d; } else { int l = 0,r = c,mid; while(l < r) { mid = (l + r) / 2; if(s[mid] < d) l = mid + 1; else r = mid; } s[l] = d; } } printf("%d\n",c); } }
然后是一种贪心做法,其实仔细去想,道理差不多,LIS是动态规划的一个知识,要求最少几个递降序列,就要求最长上升子序列,下面的贪心其实是,每次找拦截高度最接近的系统来拦截,至于那些拦截高度高的当然留给后面高度高的炮弹了,如果无法拦截,就开心的系统啊。
代码:
#include <iostream> #include <cstdio> #include <algorithm> #define inf 0x3f3f3f3f #define MAX 100000 using namespace std; int n; int s[MAX]; int main() { int d; while(~scanf("%d",&n)) { int c = 0; for(int i = 0;i < n;i ++) { scanf("%d",&d); int mini = inf,t = -1; for(int j = 0;j < c;j ++) { if(s[j] >= d && s[j] < mini) mini = s[j],t = j; } if(t == -1) s[c ++] = d; else s[t] = d; } printf("%d\n",c); } }
标签:algo 帮助 esc targe comm scan sele min col
原文地址:https://www.cnblogs.com/8023spz/p/9746345.html