46 lines
1.0 KiB
C++
46 lines
1.0 KiB
C++
/// Banu Denis - dp
|
|
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
#define ll long long
|
|
#define ld long double
|
|
#define ull unsigned long long
|
|
#define pii pair<int,int>
|
|
#define MOD 1000000007
|
|
#define zeros(x) x&(x-1)^x
|
|
#define fi first
|
|
#define se second
|
|
#define NMAX 500005
|
|
const long double PI = acos(-1);
|
|
|
|
int n,t, dp[2][4];
|
|
string s;
|
|
|
|
int main(){
|
|
ios::sync_with_stdio(false);
|
|
cin >> t;
|
|
while (t--) {
|
|
cin >> n;
|
|
cin >> s;
|
|
memset(dp,0,sizeof(dp));
|
|
int crt = 1;
|
|
for (int i=0;i<s.size();i++) {
|
|
crt = (crt^1);
|
|
if (s[i] == '0') {
|
|
dp[crt][0] = max(dp[crt^1][0] + 1, dp[crt^1][2] + 1);
|
|
dp[crt][1] = dp[crt^1][1];
|
|
dp[crt][2] = max(dp[crt^1][3] + 1, dp[crt^1][2]);
|
|
dp[crt][3] = dp[crt^1][3];
|
|
} else {
|
|
dp[crt][0] = dp[crt^1][0];
|
|
dp[crt][1] = max(dp[crt^1][0] + 1, dp[crt^1][1]);
|
|
dp[crt][2] = dp[crt^1][2];
|
|
dp[crt][3] = max(dp[crt^1][3] + 1, dp[crt^1][1] + 1);
|
|
}
|
|
}
|
|
|
|
cout << n - max({dp[crt][0], dp[crt][1], dp[crt][2], dp[crt][3]}) << '\n';
|
|
}
|
|
|
|
return 0;
|
|
} |