九度oj 1120全排列
2014-04-24 17:07
204 查看
1。STL实现
#include <stdio.h> #include <algorithm> #include <string.h> using namespace std; int main() { char s[10]; while (scanf("%s", s) != EOF) { int n = strlen(s); do { puts(s); } while (next_permutation(s, s + n)); printf("\n"); } return 0; }
2.dfs实现
#include <stdio.h> #include <string.h> char s[10]; bool visited[10]; int n; void DFS(char a[], int len) { int i; if (len == n) { a = '\0'; printf(a); printf("\n"); return; } for (i = 0; i < n; i++) { if (!visited[i]) { visited[i] = true; a[len] = s[i]; DFS(a, len + 1); visited[i] = false; } } } int main() { while (scanf("%s", s) != EOF) { char a[10]; memset(visited, 0, sizeof(visited)); n = strlen(s); DFS(a, 0); printf("\n"); } return 0; }
相关文章推荐
- 九度OJ 题目1120:全排列
- 九度OJ 1120 全排列 -- 实现C++STL中next_permutation()
- 九度OJ 1120 全排列 -- 实现C++STL中next_permutation()
- 九度OJ 教程91 回溯算法之《全排列》
- 九度oj 1120 递归(dfs)
- 九度OJ-1120-全排列
- 1120. Friend Numbers (20)
- n皇后问题的两种方法:常规的回溯法和利用全排列的回溯法
- 【复试练习】九度OJ
- 九度oj 1176 树查找
- Smallest Difference(暴力全排列)
- 【LeetCode41-50】找出丢失最小正整数,计算蓄水量,检测?*匹配(44),跳跳棋,全排列,矩阵逆转,颠倒字母重新排序(auto,set/multiset,vector初始化),n次方
- 九度OJ-题目1014 排名
- 凑算式-蓝桥-全排列
- 全排列以及含重复数的全排列
- 九度oj题目1168:字符串的查找删除
- 九度OJ题目1074:对称平方数
- 九度OJ题目1172:哈夫曼树
- 题目1183:守形数 九度OJ
- 递归实现全排列(一)