aab aba baa(思维+组合数)

Posted thusloop

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了aab aba baa(思维+组合数)相关的知识,希望对你有一定的参考价值。

在这里插入图片描述

总的个数为 a+b 中取 a 个 即 dp [a+b][a] ,第一位为 a 的个数为 dp[a+b-1][a - 1] (也就是字典序在前面)
1,若 k < = dp[a+b-1][a-1] 则第一位为 a
2 若 k > dp[a+b-1][a-1] 则第一位为b

#include<bits/stdc++.h>
#define int long long
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf=2e18+100;
int dp[100][100];
void init()//求组合数 
{
	for(int i=1;i<=60;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(i==j||j==0)dp[i][j]=1;
			else dp[i][j]=dp[i-1][j]+dp[i-1][j-1];
		}
	}
}
signed main()
{
	init();
	int a,b,k;
	cin>>a>>b>>k;
	while(a&&b)
	{
		if(k<=dp[a+b-1][a-1])
		{
			cout<<'a';
			a--;
		}
		else 
		{
			cout<<'b';
			k-=dp[a+b-1][a-1];
			b--;
		}
	}
	while(a--)cout<<'a';
	while(b--)cout<<'b';
	cout<<"\\n";
}

以上是关于aab aba baa(思维+组合数)的主要内容,如果未能解决你的问题,请参考以下文章

aab aba baa abc202

AtCoder Beginner Contest 202 D - aab aba baa(组合计数,字典序)

AISing Programming Contest 2021(AtCoder Beginner Contest 202)D - aab aba baa

No repeats please

No repeats please(freecodecamp高级算法6)

js-FCC算法-No repeats please字符串的全排列