解题思路:
注意事项:
参考代码:
#include<iostream>
#include<algorithm>
using namespace std;
char b[50];
char a[100];
int M, N;
int num;
int ans = 0;
void judge()
{
int x = num;
int m = 0, n = 0;
for(int i = 0; i < x; i++){
b[i] = a[i];
if(a[i] = 'A'){
n++;
}
else {
m++;
}
}
while(x--){
for (int i = 0;i < x; i++){
if (b[i] == b[i+1]){
n++;
b[i] = 'A';
}
else{
m++;
b[i] = 'B';
}
}
}
if(m == M && n == N){
ans++;
}
}
void dfs(int x)
{
if(x == num)
{
judge();
return ;
}
for (char i='A';i<='B';i++)
{
a[x]=i;
dfs(x+1);
}
}
int main()
{
cin >> M >> N;
for(int i = 1; i < 500; i++)
{
if ((i + 1) * (i)/2 == N + M)
{
num = i;
break;
}
}
dfs(0);
cout << ans;
return 0;
}
0.0分
0 人评分