小美的01串翻转
#include<iostream>
#include<cstring>
#include<string>
#include<vector>using namespace std;
typedef long long ll;
const int N = 1100;
string s;
ll res = 0;int main()
{cin>>s;int n = s.size();vector<vector<int>> dp(n,vector<int>(2));for (int i = 0; i < n; i++) {for (int j = i; j < n; j++) {if (j == i) {if (s[j] == '0') {dp[j] = {0,1};}else{dp[j] = {1,0};}}else{if (s[j] == '0') {dp[j][0] = dp[j-1][1];dp[j][1] = dp[j-1][0] + 1;}else {dp[j][0] = dp[j-1][1] + 1;dp[j][1] = dp[j-1][0];}}res += min(dp[j][0], dp[j][1]);}}cout << res << endl;return 0;
}