标签:blog os io ar for 2014 sp log on
题目:求一个字符串的字母集合,能组成的不同的字符串的个数。
分析:组合,计数。求出所有字母的全排列,然后除以每个字母的内部重复排列即可。
说明:(⊙_⊙)
#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> using namespace std; int times[26]; char str[25]; long long ans; long long fac(int n) { long long value = 1LL; for (int k = 2 ; k <= n ; ++ k) value *= k; return value; } int main() { int n,len; while (~scanf("%d",&n)) for (int t = 1 ; t <= n ; ++ t) { scanf("%s",str); len = strlen(str); for (int j = 0 ; j < 26 ; ++ j) times[j] = 0; ans = fac(len); for (int j = 0 ; j < len; ++ j) times[str[j]-'A'] ++; for (int j = 0 ; j < 26 ; ++ j) if (times[j] > 0) ans /= fac(times[j]); printf("Data set %d: %lld\n",t,ans); } return 0; }
UVa 10338 - Mischievous Children
标签:blog os io ar for 2014 sp log on
原文地址:http://blog.csdn.net/mobius_strip/article/details/39121109