CodeForces每日好题10.14

   给你一个字符串 让你删除一些字符让它变成一个相邻的字母不相同的字符串,问你最小的删除次数 以及你可以完成的所有方/案数

求方案数往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<bits/stdc++.h>
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<str.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<<str.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<<ans<<"\n";

	
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _;cin>>_;
	while(_--)solve();
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值