Add Again UVA

题意:

输入n个数字,求这些数字 所有全排列的和 (1<= n <= 12)

 对于任意一个数字,其在每一位出现的次数是相同的    即所有数字的每一位相加的和是相同的。

因此可以等效为它们的平均数出现的次数,而出现的次数就是重复排列的组合数,最后再乘以n个1即可得到答案。比如一个序列是{1,1,2},那么平均数就是(1+1+2)/3=4/3。出现的次数就是P(3,3)/P(2,2)=3,一共有3个1,那么ans=(4/3)*3*111=444。

整合自:http://www.cnblogs.com/zarth/p/6683651.html

https://blog.csdn.net/u014800748/article/details/45914973

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 10010, INF = 0x7fffffff;
const LL dir[13] = {0, 1, 11, 111, 1111, 11111, 111111, 1111111, 11111111,111111111, 1111111111, 11111111111, 111111111111};
int a[50], vis[maxn];
int main()
{
    a[0] = 1;
    for(int i=1; i<14; i++)
        a[i] = a[i-1] * i;
    int n;
    while(cin>> n && n)
    {
        LL temp;
        mem(vis, 0);
        LL res = 0;
        for(int i=0; i<n; i++)
            cin>> temp, res += temp, vis[temp]++;
        res = res * a[n-1];     //除以n的部分和n!约分,得到(n-1)!
        for(int i=0; i<10; i++)
            res /= a[vis[i]];
        cout<< res * dir[n] <<endl;
    }
    return 0;
}
自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
原文地址:https://www.cnblogs.com/WTSRUVF/p/9319729.html