花落


私信TA

用户名:aaa888ii

访问量:24045

签 名:

我胡汉三又回来了!

等  级
排  名 350
经  验 5128
参赛次数 3
文章发表 41
年  龄 18
在职情况 学生
学  校 东莞理工学院
专  业 软件工程

  自我简介:

喵喵喵?

解题思路:





注意事项:





参考代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<cctype>
#include<cstdlib>
using namespace std;
 char *sz,*line;
int count1 = 0;
int n;
bool judge(char a,int n)
{
	for(int i=1;i<n;i++)
	{
		if(line[i] == a) return false;
	}
	return true;
}
void dfs(int t)
{
	if(t<=n){
	for(int j=1;j<n;j++)
	{
		if(judge(sz[j],t))
		{
		if(line[t-1]-sz[j]>=-2&&line[t-1]-sz[j]<=2)
		{
			
			line[t] = sz[j];
			if(t==n-1) {count1++;}
			dfs(t+1);
			}
		}
	}
	}
}

int main()
{

	cin>>n;
	sz = new(char [n+1]);
	line = new(char [n+1]);
	line[0] = '1';
	int i = 0;
	for(char t='1';i<n;i++,t++)
	{sz[i] =t;line[i+1] = '\0';}
	sz[n] = '\0';
	dfs(1);
	cout<<count1;
	return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区