标签:recommend 阶段 sam target 分享 ssi source cep desc
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1257
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 45924 Accepted Submission(s): 18118
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5; 4 5 int use[maxn], a[maxn]; 6 7 int main() 8 { 9 int n; 10 while(scanf("%d",&n)!=EOF) 11 { 12 for(int i = 1; i<=n; i++) 13 scanf("%d",&a[i]); 14 15 int cnt = 0; 16 for(int i = 1; i<=n; i++) 17 { 18 int k = -1, minn = 2e9; 19 for(int j = 1; j<=cnt; j++) 20 if(use[j]>a[i] && use[j]<minn) 21 minn = use[k = j]; 22 23 if(k==-1) 24 use[++cnt] = a[i]; 25 else 26 use[k] = a[i]; 27 } 28 printf("%d\n",cnt); 29 } 30 31 return 0; 32 }
LIS:
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5; 4 5 int use[maxn], a[maxn]; 6 7 int main() 8 { 9 int n; 10 while(scanf("%d",&n)!=EOF) 11 { 12 13 for(int i = 1; i<=n; i++) 14 scanf("%d",&a[i]); 15 16 int cnt = 0; 17 for(int i = 1; i<=n; i++) 18 { 19 if(i==1 || a[i]>use[cnt]) 20 use[++cnt] = a[i]; 21 22 else 23 { 24 int id = lower_bound(use+1,use+1+cnt,a[i]) - (use+1); 25 use[id+1] = a[i]; 26 } 27 } 28 printf("%d\n",cnt); 29 } 30 31 return 0; 32 }
HDU1257 最少拦截系统 —— 贪心 or LIS(最长上升子序列)
标签:recommend 阶段 sam target 分享 ssi source cep desc
原文地址:http://www.cnblogs.com/DOLFAMINGO/p/7620381.html