#include<iostream> using namespace std; int source[]={1,2,3,4,5,6,7,8,9},n=9,m=3,record[10],visited[10],counter=0; void output() { for(int i=0;i<m;i++) cout<<record[i]<<" "; cout<<endl; } void dfs(int step) { if(step==m) { output(); counter++; return ; } for(int i=0;i<n;i++) { if(visited[i]==0) { visited[i]=1; record[step]=source[i]; dfs(step+1); visited[i]=0; } } } int main() { dfs(0); cout<<counter<<endl; return 0; }
时间: 2024-10-14 20:59:22