2016-05-26 Problem Solving►UVa UVa 10098 - Generating Fast Contents 1. Problem2. Solution3. Code Problem題目網址中文網址 Solution先 sort 原字串後,做 backtracking 即可。 CodeUVa 10098UVa 10098 - Generating Fast123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#include<cstdio>#include<algorithm>#include<cstring>#define N 12using namespace std;bool used[N];int len;char now[N], str[N];void backtracking(int n);int main(){ int Case; scanf("%d", &Case); getchar(); while (Case--) { gets(str); len = strlen(str); fill(used, used + len, false); sort(str, str + len); backtracking(0); putchar('\n'); } return 0;}void backtracking(int n){ int i; if (n == len) { now[n] = '\0'; puts(now); } else { char last = '\0'; for (i = 0; i < len; i++) { if (!used[i] && str[i] != last) { used[i] = true; now[n] = str[i]; last = str[i]; backtracking(n + 1); used[i] = false; } } }} Newer UVa 153 - Permalex Older UVa 11942 - Lumberjack Sequencing