其他分享
首页 > 其他分享> > HDU 1257 最少拦截系统

HDU 1257 最少拦截系统

作者:互联网

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257

分析:对于每一个位置(i),向前找是否存在比它小(或者相等的数)记为j,如果存在,那i必然相较与j得多开一个拦截系统;

 1 #include<iostream>
 2 #include<sstream>
 3 #include<cstdio>
 4 #include<cstdlib>
 5 #include<string>
 6 #include<cstring>
 7 #include<algorithm>
 8 #include<functional>
 9 #include<iomanip>
10 #include<numeric>
11 #include<cmath>
12 #include<queue>
13 #include<vector>
14 #include<set>
15 #include<cctype>
16 #define PI acos(-1.0)
17 const int INF = 0x3f3f3f3f;
18 const int NINF = -INF - 1;
19 const int maxn = 3e4 + 5;
20 typedef long long ll;
21 using namespace std;
22 int a[maxn], dp[maxn];
23 int main()
24 {
25     int n;
26     while (scanf("%d", &n) != EOF)
27     {
28         int ans = 0;
29         for (int i = 0; i < n; ++i)
30             scanf("%d", &a[i]);
31         for (int i = 0; i < n; ++i) dp[i] = 1;
32         for (int i = 0; i < n; ++i)
33         {
34             for (int j = 0; j < i; ++j)
35             {
36                 if (a[j] <= a[i])
37                     dp[i] = max(dp[j] + 1, dp[i]);
38             }
39             ans = (max(ans, dp[i]));
40         }
41         //for (int i = 0; i < n; ++i) cout << dp[i] << ' ';
42         //cout << endl;
43         printf("%d\n", ans);
44     }
45     return 0;
46 }

 

 

标签:HDU,const,int,++,1257,maxn,拦截,include,INF
来源: https://www.cnblogs.com/veasky/p/11426162.html