UVa 10063 - Knuth's Permutation
来源:互联网 发布:kanthal a1数据 编辑:程序博客网 时间:2024/06/05 04:49
题目:克努斯序列,生成排列组合的方法。
初始一个空串,每次用新的字符插入到上一次的所有串的组合情况中。
分析:递归、链表。利用链表储存,直接递归求解即可。
说明:貌似最后一组输出后有没有空格都可以,貌似没有空行的数据。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;char data[11];char save[3628800][11];int used[11];typedef struct noded{char data;noded* next;}dnode;dnode D[11];dnode* Head;int Count;void dfs( int d, int n ){if ( d == n ) {dnode* p = Head;for ( int i = 0 ; i < n ; ++ i ) {save[Count][i] = p->data;p = p->next;}save[Count ++][n] = 0;return;}dnode *p = Head,*q = p;for ( int i = 0 ; i <= d ; ++ i ) {//插点 D[d].data = data[d];D[d].next = p;if ( !i ) Head = &D[d];else q->next = &D[d];//递归 dfs( d+1, n );//回溯 if ( !i ) Head = p;else q->next = p;q = p;if ( i < d ) p = p->next;}}int main(){int count = 0; while ( scanf("%s",data) != EOF ) {if ( count ++ ) printf("\n");Count = 1;memset( save, 0, sizeof(save) );dfs( 0, strlen(data) );for ( int i = 1 ; i < Count ; ++ i )printf("%s\n",save[i]);}return 0;}
0 0
- UVa 10063 - Knuth's Permutation
- Knuth's 33 Constants
- Knuth's breaking algorithm
- sudoku--Knuth's Algorithm X
- uva-10252-Common Permutation
- UVa 10252 Common Permutation
- uva 10252Common Permutation
- UVA 11027 Palindromic Permutation
- Uva 10252 - Common Permutation
- Uva-11525-Permutation
- UVA 11525 Permutation
- UVA - 11027 Palindromic Permutation
- UVa 10252 - Common Permutation
- uva 11525 Permutation
- UVA - 11525 Permutation
- UVa 482 - Permutation Arrays
- Uva 11525 Permutation
- uva 11027 Palindromic Permutation
- 第02讲-正则表达式初步_分散字符串
- DP-K 好数
- SP2010开发和VS2010专家"食谱"--第四章节—列表定义和内容类型(6)--创建外部内容类型
- 前后端分离的思考与实践(转载)
- 华为开放亚太首个OpenDaylight实验室――被纳入OpenDaylight官方Community Labs 获高度肯定
- UVa 10063 - Knuth's Permutation
- 第02讲-正则表达式进阶_展开串
- Android Volley 之自定义Request
- 第02讲-加密与解密_设计程序
- SP2010开发和VS2010专家"食谱"--第四章节—列表定义和内容类型(7)--创建列表定义
- TEST
- 笔记:在CentOS 5.8中通过yum安装Redis
- S3C2440系统时钟
- hdu3714 水三分