码迷,mamicode.com
首页 > 其他好文 > 详细

贪心 Codeforces Round #191 (Div. 2) A. Flipping Game

时间:2015-07-18 19:55:35      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

 1 /*
 2     贪心:暴力贪心水水    
 3 */
 4 #include <cstdio>
 5 #include <algorithm>
 6 #include <cstring>
 7 using namespace std;
 8 
 9 const int MAXN = 1e2 + 10;
10 const int INF = 0x3f3f3f3f;
11 int a[MAXN];
12 
13 int main(void)      //Codeforces Round #191 (Div. 2) A. Flipping Game
14 {
15     int n;    scanf ("%d", &n);
16     int sum = 0;
17     for (int i=1; i<=n; ++i)    scanf ("%d", &a[i]), sum += a[i];
18 
19     int ans = 0;
20     for (int i=1; i<=n; ++i)
21     {
22         for (int j=1; j<=n-i+1; ++j)
23         {
24             int pre = 0;    int now = 0;
25             for (int k=j; k<=j+i-1; ++k)
26             {
27                 pre += a[k];    now += 1 - a[k];
28             }
29             ans = max (ans, sum - pre + now);
30         }
31     }
32 
33     printf ("%d\n", ans);
34 
35 
36     return 0;
37 }

 

贪心 Codeforces Round #191 (Div. 2) A. Flipping Game

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4657346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!