【补题】Educational Codeforces Round 107 (Rated for Div. 2) D. Min Cost String

题意:要求你给出一个长度为n的字符串,其中只能出现小写字母的前k个字符。要求s[i]==s[j],s[i+1]==s[j+1]出现的次数最少。

思路:D. Min Cost String(贪心+构造)-CSDN博客

因为没有距离贡献之类的,所以让两个连着字符的字符出现最少就可以了。
但是光考虑aa ab ba这种不行,因为你构造出来的字符串可能无意中出现了相同。
直接思考最好的字符串其实就是a ab ac ad    b bc bd,用完了直接循环。
其实就是贪心,让结构出现越少越好

代码:

#include 
#define int long long
#define IOS std::ios::sync_with_stdio(0);std::cin.tie(0);std::cout.tie(0)

const int MOD=1e9+7;
const int N=1e7+10;



void solve(){

	int n,k;
	std::cin >> n >> k;

	std::string s;

	for(int i=0;i> t;
	while(t--){
		solve();
	}
}

你可能感兴趣的:(算法)