
给你一个字符串 让你删除一些字符让它变成一个相邻的字母不相同的字符串,问你最小的删除次数 以及你可以完成的所有方/案数
求方案数往DP 或者 组合数学推公式上面去想,发现一个有意思的事情
例如1001011110
这个字符串你划分成1 00 1 0 1111 0
每个部分最多剩余一个
最小操作数就是n-划分个数
方案数的话自己玩一下 简单的组合数学推公式
- // Problem: C. Make it Alternating
- // Contest: Codeforces - Educational Codeforces Round 155 (Rated for Div. 2)
- // URL: https://codeforces.com/problemset/problem/1879/C
- // Memory Limit: 256 MB
- // Time Limit: 2000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
-
- #include
- using namespace std;
- using ll=long long;
- const int N = 2e5+10,mod = 998244353;
- ll ans=1;
- void solve()
- {
- string str;cin>>str;
- vector<int>arr;
- string tem="";
- tem+=str[0];
- for(int i=1;i
size();i++){ - if(str[i]!=str[i-1]){
- arr.push_back(tem.size());
- tem="";
- }
- tem+=str[i];
- }
- if(tem!="")arr.push_back(tem.size());
-
-
- cout<
size()-arr.size()<<" "; -
-
- ans = 1;
- for(auto t:arr) ans = ans*t%mod;
- int t = str.size()-arr.size();
- for(int i=1;i<=t;i++) ans = ans * i %mod;
-
- cout<
"\n"; -
-
- }
-
- int main()
- {
- ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
- int _;cin>>_;
- while(_--)solve();
- return 0;
- }