题目链接:UVA-33478

题意为给定n个数,求这n个数能组成的所有不同的排列组成的数字的和。

思路:发现对于任意一个数字,其在每一位出现的次数是相同的。换言之,所有数字的每一位相加的和是相同的。

所以我们只需求出这个“和”即可。

考虑任意一位i,假设我们在i位放置x,则对应\( (n-1)! / ( d_0! * d_1! * ... * d_x! * ... * d_9! ) \)种情况。

所以我们要求的“和”等于\(\sum_x x * (n-1)! / ( d_0! * d_1! * ... * d_x! * ... * d_9! )\)。

代码如下:

 #include"cstdio"
#include"iostream"
#include"cstring"
#include"algorithm"
#include"cstdlib"
#include"vector"
#include"set"
using namespace std;
typedef unsigned long long LL;
const LL MAXN=1e5; LL fact[];
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
fact[]=;
for(LL i=;i<;i++)
fact[i]=fact[i-]*i;
LL n;
while(scanf("%lld",&n)!=EOF && n)
{
LL d[];
memset(d,,sizeof(d));
for(LL i=;i<=n;i++)
{
LL tmp;
scanf("%lld",&tmp);
d[tmp]++;
}
LL r=;
for(LL i=;i<;i++)
if(d[i])
{
LL tmp=fact[n-];
for(LL j=;j<;j++)
{
if(j==i) tmp/=fact[d[j]-];
else tmp/=fact[d[j]];
}
r+=tmp*i;
}
LL ans=;
for(LL i=;i<=n;i++)
{
ans*=;
ans+=r;
}
printf("%lld\n",ans);
}
return ;
}

UVA 11076 Add Again的更多相关文章

  1. 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 ...

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

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

  3. UVA 11076 - Add Again(组合)

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

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

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

  5. UVa 11076 (有重元素的排列) Add Again

    n个可重复的元素的排列一共有 = All种,其中 假设这些数依次为ai,每种数字有mi个. 从右往左考虑第d位数(d≥0),第i个数字出现的次数为,那么这个数字对所求答案的贡献为 其实可以先一次求出个 ...

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

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

  7. 【NOIP合并果子】uva 10954 add all【贪心】——yhx

    Yup!! The problem name reects your task; just add a set of numbers. But you may feel yourselvesconde ...

  8. UVA 10954 Add All 哈夫曼编码

    题目链接: 题目 Add All Time Limit:3000MS Memory Limit:0KB 问题描述 Yup!! The problem name reflects your task; ...

  9. UVa 10954 Add All(优先队列)

    题意  求把全部数加起来的最小代价  a+b的代价为(a+b) 越先运算的数  要被加的次数越多  所以每次相加的两个数都应该是剩下序列中最小的数  然后结果要放到序列中  也就是优先队列了 #inc ...

随机推荐

  1. tcp协议的六个标识位

    6个标识位: URG 紧急指针,告诉接收TCP模块紧要指针域指着紧要数据. ACK 置1时表示确认号(为合法,为0的时候表示数据段不包含确认信息,确认号被忽略. PSH 置1时请求的数据段在接收方得到 ...

  2. Codeforces Gym 101142 G Gangsters in Central City (lca+dfs序+树状数组+set)

    题意: 树的根节点为水源,编号为 1 .给定编号为 2, 3, 4, …, n 的点的父节点.已知只有叶子节点都是房子. 有 q 个操作,每个操作可以是下列两者之一: + v ,表示编号为 v 的房子 ...

  3. 【BZOJ1941】Hide and Seek(KD-Tree)

    [BZOJ1941]Hide and Seek(KD-Tree) 题面 BZOJ 洛谷 题解 \(KD-Tree\)对于每个点搜一下最近点和最远点就好了 #include<iostream> ...

  4. 第一次BC

    BestCoder Round #90 1001 Kblack loves flag 太弱只写了这一道水题. 首先这个题面就是,完全不知道它在说什么.开始5mins后我还完全不知道这个题想要表达什么. ...

  5. java 实现多个接口 方法重名的解决办法——内部类

    package com.kk.innerClass; /** * 通过内部类实现接口 * 解决多个接口中方法重名问题 * */interface Machine { void run();} clas ...

  6. libudev使用说明书

    转http://blog.csdn.net/coroutines/article/details/38067805 1. 初始化 首先调用udev_new,创建一个udev library conte ...

  7. 解决webstrom 输入法光标不跟随问题

    参考博客地址 https://blog.csdn.net/wang414300980/article/details/79537875 原因是jdk版本问题,下载jdk jbsdk8u152b1036 ...

  8. Consul 入门(二)

    KV 存储 通过命令行操作 $ consul kv put hello world # 设置数据 Success! Data written to: hello $ consul kv get hel ...

  9. stout代码分析之十一:hashmap和multihashmap

    hashmap是std::unordered_map的子类,前者对后者的接口做了进一步封装. hashmap的移动构造函数: hashmap(std::map<Key, Value>&am ...

  10. git设置免密码登录

    设置用户名和邮箱 git config --global user.name "<username>" git config --global user.email & ...