Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
35164 byxx2023 【搜索与回溯】选书(例题) C++ 无测评数据 0 MS 0 KB 960 2023-12-29 17:04:05

Tests(0/0):


#include<bits/stdc++.h> using namespace std; int n=5,sum; int flag[6]; int a[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}, }; int b[6],c[6]; int fun2(int x) { if(x==1) { cout<<"A"; } else if(x==2) { cout<<"B"; } else if(x==3) { cout<<"C"; } else if(x==4) { cout<<"D"; } else { cout<<"E"; } return 0; } void print() { printf("answer %d:\n",sum); printf("Student Zhang:"); fun2(c[1]); printf("\nStudent Wang:"); fun2(c[2]); printf("\nStudent Liu:"); fun2(c[3]); printf("\nStudent Sun:"); fun2(c[4]); printf("\nStudent Li:"); fun2(c[5]); printf("\n"); } void fun1(int k) { for(int i=1;i<=5;i++) { if(flag[i]==0&&a[k][i]==1) { flag[i]=1; c[k]=i; if(k==5) { sum++; print(); } else { fun1(k+1); } flag[i]=0; } } } int main() { fun1(1); return 0; }