日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > Codeforces Round #191 (Div. 2)---A. Flipping Game

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

來源:程序員人生   發布時間:2014-11-27 08:15:07 閱讀次數:2790次

Flipping Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Iahub got bored, so he invented a game to be played on paper.

He writes n integers a1,?a2,?...,?an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1?≤?i?≤?j?≤?n) and flips all values ak for which their positions are in range [i,?j] (that is i?≤?k?≤?j). Flip the value of xmeans to apply operation x?=?1 - x.

The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub.

Input

The first line of the input contains an integer n (1?≤?n?≤?100). In the second line of the input there are n integers: a1,?a2,?...,?an. It is guaranteed that each of those n values is either 0 or 1.

Output

Print an integer ― the maximal number of 1s that can be obtained after exactly one move.

Sample test(s)
input
5 1 0 0 1 0
output
4
input
4 1 0 0 1
output
4
Note

In the first case, flip the segment from 2 to 5 (i?=?2,?j?=?5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].

In the second case, flipping only the second and the third element (i?=?2,?j?=?3) will turn all numbers into 1.







解題思路:題意是講有1個0,1序列,現允許你對任意1個子序列取反,問操作后得到的序列,最多能有多少個1。

數據不大,直接暴力。直接兩層循環枚舉取反序列的出發點和終點,統計每種情況下1的個數,保存1個最大值便可。






AC代碼:

#include <iostream> #include <cstdio> using namespace std; int a[105]; int main(){ // freopen("in.txt","r",stdin); int n; while(cin>>n){ for(int i =0; i<n; i++) cin>>a[i]; int ans = 0; for(int i=0; i<n; i++){ for(int j=i; j<n; j++){ int sum = 0; for(int k=0; k<n; k++){ if(k>=i && k<=j) sum += a[k]^1; //用異或^取反 else sum += a[k]; } if(ans < sum) ans = sum; } } cout<<ans<<endl; } return 0; }


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美精品成人一区二区三区四区 | 日韩欧美成人一区二区 | 国精产品一区二区 | 免费日韩三级 | 欧美日韩中文字幕在线视频 | 黄色aaa大片| 国产精品视频不卡 | 丁香五月网久久综合 | 91免费观看视频 | 淫片在线观看 | 欧美综合色 | 电影 在线 | 日产av在线免费观看 | 免费成人av在线 | 中文字幕www | 日韩av综合 | 国产欧美精品区一区二区三区 | 国产一区二区在线播放 | 亚洲欧美在线免费 | 日本性网站 | 最新中文字幕在线视频 | 久久嫩草精品久久久精品 | 国产日韩欧美激情 | 成人国产 | 国产免费专区 | 国产专区精品 | 麻豆乱码国产一区二区三区 | 国产成人综合在线 | 欧美久久一级 | 国产精品久久久久久久久免费看 | 久久精品国产v日韩v亚洲 | 日韩亚州 | 男操女视频在线观看 | 国产精品国产亚洲精品看不卡15 | cao在线| 欧美福利一区 | 欧美一区二区三区视频在线观看 | 懂色av蜜臀av粉嫩av分享吧 | 国产精品一区二区三区免费看 | 亚洲欧美在线视频 | 亚洲一视频 |