zoukankan      html  css  js  c++  java
  • HDU 1016

    EASY

     1 #include <iostream>
     2 #include <cstdio>
     3 using namespace std;
     4 
     5 bool prim[45];
     6 int n;
     7 bool vis[45];
     8 int ans[25];
     9 
    10 void dfs(int top){
    11     if(top>n){
    12         printf("1");
    13         for(int i=2;i<=n;i++)
    14         printf(" %d",ans[i]);
    15         printf("
    ");
    16     }
    17     if(top==n){
    18         for(int i=2;i<=n;i++)
    19         if(prim[i+ans[top-1]]&&!vis[i]&&prim[i+1]){
    20             ans[top]=i;
    21             vis[i]=true;
    22             dfs(top+1);
    23             vis[i]=false;
    24         }
    25         return ;
    26     }
    27     for(int i=2;i<=n;i++)
    28     if(prim[i+ans[top-1]]&&!vis[i]){
    29         ans[top]=i;
    30         vis[i]=true;
    31         dfs(top+1);
    32         vis[i]=false;
    33     }
    34 }
    35 
    36 int main(){
    37     memset(prim,false,sizeof(prim));
    38     prim[2]=prim[3]=prim[5]=prim[7]=prim[11]=prim[13]=true;
    39     prim[17]=prim[19]=prim[23]=prim[29]=prim[31]=prim[37]=prim[41]=true;
    40     ans[1]=1; vis[1]=true;
    41     int T=0;
    42     while(scanf("%d",&n)!=EOF){
    43         T++;
    44         printf("Case %d:
    ",T);
    45         dfs(2);
    46         printf("
    ");
    47     }
    48     return 0;
    49 }
    View Code
  • 相关阅读:
    Docker Get Started VI
    Docker Get Started V
    Docker Get Started III
    Docker Get Started IV
    Docker Get Started II
    Docker Get Started I
    贝叶斯公式
    LRU缓存
    二进制中1的个数
    2.准备工作之Gradle
  • 原文地址:https://www.cnblogs.com/jie-dcai/p/3803126.html
Copyright © 2011-2022 走看看