首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2013-03-04 
九度OJ 教程91 回溯算法之《全排列》题目地址:http://ac.jobdu.com/problem.php?cid1040&pid90//九度OJ 教

九度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;}


热点排行