多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > 互聯(lián)網(wǎng) > Codeforces Round #191 (Div. 2)---A. Flipping Game

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

來源:程序員人生   發(fā)布時(shí)間:2014-11-27 08:15:07 閱讀次數(shù):2786次

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個(gè)0,1序列,現(xiàn)允許你對(duì)任意1個(gè)子序列取反,問操作后得到的序列,最多能有多少個(gè)1。

數(shù)據(jù)不大,直接暴力。直接兩層循環(huán)枚舉取反序列的出發(fā)點(diǎn)和終點(diǎn),統(tǒng)計(jì)每種情況下1的個(gè)數(shù),保存1個(gè)最大值便可。






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; }


生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 日韩欧美高清视频 | 中文字幕乱码二三区免费 | 亚洲天堂中文字幕在线 | 精品一区二区三区免费站 | 精品视频一二三区 | 国产三级视频在线 | 国产福利不卡一区二区三区 | 亚洲视频在线观 | 亚洲欧洲日产国码在线观看 | 国产视频在线一区 | 国产成人精品无缓存在线播放 | 欧美人与牲禽ⅹxxx伦交 | 亚洲成人h | 欧美综合视频在线观看 | 免费网址在线观看 | 亚色成人 | 啪一啪在线视频 | 男女啪啪片 | 欧洲免费无线码二区5 | 视频h在线| 黑人一区二区三区中文字幕 | 日本亚洲欧美在线 | 热色综合| 国产精品亚洲欧美 | jizzjizz亚洲| 污污成人一区二区三区四区 | 欧美日韩国产精品 | 午夜影院免费观看视频 | 欧美在线成人午夜影视 | 国产福利片在线 易阳 | 女人aaaaa片一级一毛片 | 亚洲成a | www.免费观看 | 亚洲精品久久久久久久久久ty | 成人亚洲国产综合精品91 | 黄色网址免费 | 宇都宫紫苑在线 | 中文字幕组| 日本番囗 | 欧美成人综合在线观看视频 | 三级天堂 |