Title Link: Http://www.codeforces.com/problemset/problem/327/A
Test instructions: You now have n cards, these are 0 on one side and 1 on the other side. Numbering from 1 to n, you need to flip the [i,j] interval of the card once, so that the number of cards seen is 1 of the largest.
C + + code:
#include <iostream>using namespacestd;Const intMAXN = the;intN, A[maxn], SUM[MAXN];intFlipintLintR) { intA1 = Sum[r]-sum[l-1]; intA2 = R-l +1-A1; //cout << "a1=" << A1 << "; A2= "<< A2 <<"; ["<< L <<", "<< R <<"] = = "<< sum[n]-sum[r] + sum[l-1] + A2 << Endl; returnSum[n]-sum[r] + sum[l-1] +A2;}intMain () {CIN>>N; for(inti =1; I <= N; i + +) {cin>>A[i]; Sum[i]= sum[i-1] +A[i]; } intans = min (sum[n]+1, N-1); for(inti =1; I <= N; i + +) for(intj = i; J <= N; J + +) ans=max (ans, Flip (i, j)); cout<<ans; return 0;}
C + +
Codeforces Water Question 100 The 20th question codeforces Round #191 (Div. 2) A. Flipping Game (brute force)