[HDOJ1261]最少攔截系統

來源:互聯網
上載者:User

標籤:

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=1257

 

dp數組記錄某套攔截系統當前可以攔截的高度。

貪心可過,每讀入一個飛彈高度,和之前能打到的最低的比較,如果飛彈比之前的高,那就要增加一套攔截系統,並且將此飛彈的高度記錄下來。如果比之前的低,那麼讓最近的比它高的那套攔截系統攔截它,並且更改那一套的dp值。

 

 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #include <algorithm> 5 #include <iostream> 6 #include <cmath> 7 #include <queue> 8 #include <map> 9 #include <set>10 #include <stack>11 #include <list>12 #include <vector>13 14 using namespace std;15 16 const int maxn = 30010;17 int n;18 int tmp;19 int dp[maxn];20 21 int main() {22     // freopen("in", "r", stdin);23     while(~scanf("%d", &n)) {24         int cnt = 1;25         int flag = 0;26         while(n--) {27             scanf("%d", &tmp);28             if(!flag) {29                 dp[0] = tmp;30                 flag = 1;31             }32             int i;33             for(i = 0; i < cnt; i++) {34                 if(tmp <= dp[i]) {35                     dp[i] = tmp;36                     break;37                 }38             }39             if(i == cnt) {40                 dp[cnt++] = tmp;41             }42         }43         printf("%d\n", cnt);44     }45 }

 

[HDOJ1261]最少攔截系統

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.