Topic URL
https://ac.nowcoder.com/acm/contest/46800/K
Attached picture (click to view larger picture)
But I didn't use dp, I summed up the rules and wrote it
In fact, after thinking about it, you can figure out that when the character is 100100100100... In this way, the total number of bad intervals is the least, just consider the last paragraph, because there is no bad interval before
Just consider the last case of the string
...100100
...100101
...100111
...101111
There are probably only a few types, and you will find that there are bad intervals from a certain position, as long as you find that position.
Of course, don't forget to consider the case of n==m! ! !
#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if(n==m){
cout<<n-2;
}else if((n-1)/3+1>=m){
cout<<0;
}else{
cout<<m-((n-m)/2+1);
}
}