题意:

输入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 = , INF = 0x7fffffff;
const LL dir[] = {, , , , , , , , ,, , , };
int a[], vis[maxn];
int main()
{
a[] = ;
for(int i=; i<; i++)
a[i] = a[i-] * i;
int n;
while(cin>> n && n)
{
LL temp;
mem(vis, );
LL res = ;
for(int i=; i<n; i++)
cin>> temp, res += temp, vis[temp]++;
res = res * a[n-]; //除以n的部分和n!约分,得到(n-1)!
for(int i=; i<; i++)
res /= a[vis[i]];
cout<< res * dir[n] <<endl;
}
return ;
}

Add Again UVA - 11076(排列之和)的更多相关文章

  1. LA 3641 Leonardo的笔记本 & UVA 11077 排列统计

    LA 3641 Leonardo的笔记本 题目 给出26个大写字母的置换B,问是否存在要给置换A,使得 \(A^2 = B\) 分析 将A分解为几个循环,可以观察经过乘积运算得到\(A^2\)后,循环 ...

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

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

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

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

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

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

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

  6. UVA 11076 Add Again

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

  7. UVA 11076 - Add Again(组合)

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

  8. [Leetcode] Add two numbers 两数之和

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...

  9. 数论 UVA 11076

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

随机推荐

  1. Hadoop Version History and Feature

    Versions and Features Hadoop has seen significant interest over the past few years. This has led to ...

  2. Storm 运行例子

    1.建立Java工程 使用idea,添加lib库,拷贝storm中lib到工程中 2.拷贝wordcount代码 下载src包,解压找到 apache-storm-0.9.4-src\apache-s ...

  3. 20155339 Exp3 免杀原理与实践

    20155339 Exp3 免杀原理与实践 基础问题 (1)杀软是如何检测出恶意代码的? 基于特征码的检测(杀软的特征库中包含了一些数据或者数据段,杀软会尽可能的更新这个特征库,以包括尽可能多的恶意代 ...

  4. VBA how to crack Excel Password

    来源 更多vba相关 vba教程 VBA cheat sheet 1. VBA how to crack Excel Workbook/Worksheet password To remove the ...

  5. python 回溯法 子集树模板 系列 —— 2、迷宫问题

    问题 给定一个迷宫,入口已知.问是否有路径从入口到出口,若有则输出一条这样的路径.注意移动可以从上.下.左.右.上左.上右.下左.下右八个方向进行.迷宫输入0表示可走,输入1表示墙.为方便起见,用1将 ...

  6. 【第六课】Nginx常用配置下详解

    目录 Nginx常用配置下详解 1.Nginx虚拟主机 2.部署wordpress开源博客 3.部署discuz开源论坛 4.域名重定向 5.Nginx用户认证 6.Nginx访问日志配置 7.Ngi ...

  7. vs2017 用 nuget发布包时报错

    安装了 vs2017后, 发布nuget 时报错: Failed to load msbuild Toolset 未能加载文件或程序集"Microsoft.Build, Version=14 ...

  8. linux之grep 基础

    第一章 -a    将binary文件以text文件的方式搜寻数据-c    只输出匹配行的计数,计算找到匹配的次数-I(大写i)    不区分大小写(只适合用于单字符)-h    查询多文件时不显示 ...

  9. 激活IntelliJ IDEA到2100年

    1.下载破解文件(破解版本2018.2,其他版本未尝试) http://idea.lanyus.com/jar/JetbrainsIdesCrack-4.2-release-sha1-3323d5d0 ...

  10. 更改jenkins的默认工作空间并迁移插件和配置数据

    最近刚使用阿里云ECS centos服务器,购买的是40G的系统盘,60G的数据盘. 昨天在查看服务器磁盘空间的时候,偶然发现 /dev/vda1 下面40G的空间已使用17G, 因为服务器才开始使用 ...