记录编号 199657 评测结果 AAAAA
题目名称 [HAOI 2004模拟]数列问题 最终得分 100
用户昵称 Gravatarliu_runda 是否通过 通过
代码语言 C++ 运行时间 0.028 s
提交时间 2015-10-27 09:47:30 内存使用 0.29 MiB
显示代码纯文本
#include<cstdio>
using namespace std;
bool notP[50]={1,1,0,0,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1};
int seq[15];
bool used[16];
int len;
int sol = 0;
void output(){
	for(int i = 0;i<len-1;++i)
	    printf("%d ",seq[i]);
	printf("%d\n",seq[len-1]);
}
void dfs(int pos){//enumerate num at seq[pos]
	if(pos == len){
		++sol;
		output();
		return;
	}else{
		for(int i = 1;i<=len;++i){
			if((pos == 0||!used[i]&&!notP[seq[pos-1]+i])){
				used[i] = true;
				seq[pos] = i;
				dfs(pos+1);
				used[i] = false;
			}
		}
	}
}
int main(){
	freopen("dfs3.in","r",stdin);
	freopen("dfs3.out","w",stdout);
	scanf("%d",&len);
	dfs(0);
	printf("%d",sol);
	fclose(stdin);fclose(stdout);
	return 0;
}