dd爱科学1.0javascript:void(0);
dd爱科学1.0
https://ac.nowcoder.com/acm/contest/11211/A
贪心:修改的的位数越小越好 那么n-最长非递减子序列的长度即是最小修改的位数
#include<bits stdc++.h>
using namespace std;
const int N = 1e6+10;
int n;
int a[N],low[N];
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int main()
{
fast;
cin >> n;
for (int i = 1; i <= n; ++i)
{
char ch;
cin >> ch;
a[i] = ch - 'A';
low[i] = 0x3f3f3f3f;
}
low[1] = a[1];
int ans = 1;
for (int i = 2; i <= n; ++i)
{
if (a[i] >= low[ans])
low[++ans] = a[i];
else
{
int j = upper_bound(low + 1, low + ans + 1, a[i]) - low;
low[j] = a[i];
if (j > ans) ++ans;
}
}
cout << n-ans << endl;
return 0;
}