真是简单易懂啊!马上就会了
#include <bits/stdc++.h>
using namespace std;
int n, s1 = 0, s2 = 0, s3 = 0, s4 = 0;
int main() {
scanf("%d", &n);
while (n--) {
int x;
scanf("%d", &x);
if (x == 1) {
s1++;
s3 = max(s3 + 1, s2 + 1);
} else {
s2 = max(s1 + 1, s2 + 1);
s4 = max(s3 + 1, s4 + 1);
}
}
printf("%d\n", max(s3, s4));
return 0;
}