读书人

9度OJ 教程91 回溯算法之《全排列》

发布时间: 2013-03-04 17:22:12 作者: rapoo

九度OJ 教程91 回溯算法之《全排列》

题目地址:http://ac.jobdu.com/problem.php?cid=1040&pid=90



//九度OJ 教程91 回溯算法之《全排列》//http://ac.jobdu.com/problem.php?cid=1040&pid=90#include <stdio.h>#include<string.h>#define MAXS 8int mark[MAXS],count,lenth;char ans[MAXS],h[MAXS];void huisu(int k){if(k==lenth){puts(ans);return;}for(int i=0;i<lenth;i++){if(mark[i]){mark[i]=0;ans[count++]=h[i];huisu(count);mark[i]=1;count--;}}}int main(){while(~scanf("%s",h)){lenth=strlen(h);memset(mark,1,MAXS*sizeof(int));memset(ans,0,MAXS*sizeof(char));huisu(count=0);printf("\n");}return 0;}


读书人网 >编程

热点推荐