码迷,mamicode.com
首页 > 其他好文 > 详细

先修倒计时——五天

时间:2016-04-11 18:16:12      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

搜索联系第一发——质数环

#include<iostream>
#include<cstdio>
using namespace std;
int a[40]={0};
int b[18],kg[18]={0};
int n,l=1;
void dfs(int i){
    int j;
    if(l==n&&a[1+b[n]]==1){
        for(j=1;j<=n;j++){
            cout<<b[j];
            cout<< ;
        }
        cout<<endl;
    }
    for(j=2;j<=n;j++){
        if(kg[j]==0&&a[j+b[l]]==1){
            kg[j]=1;
            l++;
            b[l]=j;
            dfs(j);
            kg[j]=0;
            l--;
        }
    }
    
}
int main(){
    cin>>n;
    a[2]=1;a[3]=1;a[5]=1;a[7]=1;
    a[11]=1;a[13]=1;a[17]=1;a[19]=1;a[23]=1;a[29]=1;a[31]=1;
    b[1]=1;
    kg[1]=1;
    dfs(2);
}

搜索练习第二发——四子连棋

先修倒计时——五天

标签:

原文地址:http://www.cnblogs.com/liuxinyu/p/5379329.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!