n个可重复的元素的排列一共有 = All种,其中

假设这些数依次为ai,每种数字有mi个。

从右往左考虑第d位数(d≥0),第i个数字出现的次数为,那么这个数字对所求答案的贡献为

其实可以先一次求出个位上每种数字对答案的贡献,然后乘上

 #include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL; const int maxn = ;
LL fac[maxn + ], pow10[maxn + ];
int a[maxn + ], b[maxn + ], num[maxn + ]; int main()
{
//freopen("in.txt", "r", stdin); fac[] = pow10[] = ;
for(int i = ; i <= maxn; i++) { fac[i] = fac[i-] * i; pow10[i] = pow10[i-] * ; }
for(int i = ; i <= maxn; i++) pow10[i] += pow10[i - ]; int n;
while(scanf("%d", &n) == && n)
{
for(int i = ; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
int cnt = ;
for(int i = ; i < n;)
{
int j = i;
while(j < n && a[j] == a[i]) j++;
b[cnt] = a[i]; num[cnt++] = j - i;
i = j;
}
LL all = fac[n];
for(int i = ; i < cnt; i++) all /= fac[num[i]];
LL sum = ;
for(int i = ; i < cnt; i++) sum += b[i] * num[i] * all / n;
printf("%lld\n", sum * pow10[n-]);
} return ;
}

代码君

UVa 11076 (有重元素的排列) Add Again的更多相关文章

  1. Add Again UVA - 11076(排列之和)

    题意: 输入n个数字,求这些数字 所有全排列的和 (1<= n <= 12) 对于任意一个数字,其在每一位出现的次数是相同的    即所有数字的每一位相加的和是相同的. 因此可以等效为它们 ...

  2. UVA 11076 Add Again 计算对答案的贡献+组合数学

    A pair of numbers has a unique LCM but a single number can be the LCM of more than one possiblepairs ...

  3. 【数论-数位统计】UVa 11076 - Add Again

    Add AgainInput: Standard Input Output: Standard Output Summation of sequence of integers is always a ...

  4. Uva 11076 Add Again (数论+组合数学)

    题意:给你N个数,求把他们的全排列加和为多少 思路:对于这道题,假设数字k1在第一位,然后求出剩下N-1位的排列数num1,我们就可以知道k1在第一位时 排列有多少种为kind1, 同理,假设数字k2 ...

  5. UVA 11076 Add Again

    题目链接:UVA-33478 题意为给定n个数,求这n个数能组成的所有不同的排列组成的数字的和. 思路:发现对于任意一个数字,其在每一位出现的次数是相同的.换言之,所有数字的每一位相加的和是相同的. ...

  6. UVA 11076 - Add Again(组合)

    题目链接 脑子抽了,看错题了,神奇的看成没有0了.主要问题把n个数插入m个相同的数,把m个数给分成1-m堆,然后插到n+1空里. #include <cstdio> #include &l ...

  7. 数论 UVA 11076

    这道题目的意思简单易懂说的是给你n个数(可能有重复相同的数字),列出他们所有排列的情况,再逐位相加,求出和,例如:给你1,2,3,则排列的情况为<123>, <132>, &l ...

  8. UVa 140 Bandwidth【枚举排列】

    题意:给出n个节点的图,和一个节点的排列,定义节点i的带宽b[i]为i和其相邻节点在排列中的最远的距离,所有的b[i]的最大值为这个图的带宽,给一个图,求出带宽最小的节点排列 看的紫书,紫书上说得很详 ...

  9. uva 11076

    计算出每一位上数字i会出现的次数  累加 #include <cstdio> #include <cstdlib> #include <cmath> #includ ...

随机推荐

  1. WPF解析Word为图片

    偶遇需要解析Word为单张图,此做 http://git.oschina.net/jiailiuyan/OfficeDecoder using System; using System.Collect ...

  2. Backbone.Events—纯净MVC框架的双向绑定基石

    Backbone.Events-纯净MVC框架的双向绑定基石 为什么Backbone是纯净MVC? 在这个大前端时代,各路MV*框架如雨后春笋搬涌现出来,在infoQ上有一篇 12种JavaScrip ...

  3. About the Storage allocation

    It doesn't matter what programming language u use,it's all about the usage of variable---storage man ...

  4. [book]awesome-machine-learning books

    https://github.com/josephmisiti/awesome-machine-learning/blob/master/books.md Machine-Learning / Dat ...

  5. 1452: [JSOI2009]Count - BZOJ

    Description Input Output Sample Input Sample Output 1 2HINT 一开始还想什么离线做,其实不用,空间足够,我们直接开100个二维树状数组,然后就 ...

  6. c++ freelockquque

    http://www.boost.org/doc/libs/1_56_0/doc/html/boost/lockfree/queue.html Class template queue boost:: ...

  7. SVN--VisualSVN server 服务端和 TortoiseSVN客户端的基础使用

    前言 在上一文http://www.cnblogs.com/wql025/p/5177699.html中,我们讲到了使用SVN的第一步,即下载.安装SVN的服务端软件--VisualSVN serve ...

  8. 【转】欧拉回路&特殊图下的哈密顿回路题集

    转自:http://blog.csdn.net/shahdza/article/details/7779385 欧拉回路[HDU]1878 欧拉回路 判断3018 Ant Trip 一笔画问题1116 ...

  9. 【BZOJ】【2154】Crash的数字表格

    莫比乌斯反演 PoPoQQQ讲义第4题 题解:http://www.cnblogs.com/jianglangcaijin/archive/2013/11/27/3446169.html 感觉两次sq ...

  10. windowopen

    1.最基本的弹出窗口代码] <SCRIPT LANGUAGE="javascript"> <!-- window.open ('page.html') --> ...