zoukankan      html  css  js  c++  java
  • 回溯7--选书

    回溯7--选书

    一、心得

    最简单的回溯题

    数组中还有一个符合条件的那种数组

    二、题目及分析

    三、代码及结果

     1 /*
     2 这里多了一个符合条件的标志数组 
     3 */
     4 #include <iostream>
     5 using namespace std;
     6 
     7 int like[6][6]={{0,0,0,0,0,0},{0,0,0,1,1,0},{0,1,1,0,0,1},{0,0,1,1,0,0},{0,0,0,0,1,0},{0,0,1,0,0,1}}; 
     8 int vis[6];
     9 int ans[6];
    10 int total=0;
    11 
    12 void print(){
    13     total++;
    14     cout<<total<<": "<<endl;
    15     for(int i=1;i<=5;i++){
    16         cout<<ans[i]<<" ";
    17     }
    18     cout<<endl;
    19 }
    20 
    21 void search(int step){
    22     if(step==6) print();
    23     else
    24         for(int i=1;i<=5;i++){
    25             if(!vis[i]&&like[step][i]){
    26                 ans[step]=i,vis[i]=1;
    27                 search(step+1);
    28                 vis[i]=0;
    29             }
    30         }
    31 }
    32 
    33 
    34 int main(){
    35     search(1);
    36     return 0;
    37 }

  • 相关阅读:
    ANGULAR 开发用户选择器指令
    ANGULARJS 动态编译添加到dom中
    poj1061
    poj1077
    poj1095
    poj1102
    poj1088
    血痹汤治四肢麻木
    重用白术、苡仁治腰痛
    腰间盘突出方(刘力红)
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/7124353.html
Copyright © 2011-2022 走看看