Add Again

Summation of sequence of integers is always a
common problem in Computer Science. Rather than computing blindly, some
intelligent techniques make the task simpler. Here you have to find the
summation of a sequence of integers. The sequence is an interesting one and it
is the all possible permutations of a given set of digits. For example, if the
digits are <1 2 3>, then six possible permutations are <123>,
<132>, <213>, <231>, <312>, <321> and the sum of
them is 1332.

Input

Each input set will start with a positive
integerN (1≤N≤12). The next line will contain N decimal digits. Input will be
terminated by N=0. There will be at most 20000 test set.

Output

For each test set, there should be a one line
output containing the summation. The value will fit in 64-bit unsigned
integer.

Sample
Input                               Output for Sample Input

3

1 2 3

3

1 1 2

0


1332

444


Problemsetter: Md. Kamruzzaman

Special Thanks: Shahriar Manzoor

思路:对于第x位,一共有k个元素,其中第i个元素有ni个,求全排列个数:全排列个数=(n-1)!/(n1!*n2!*n3!*n4!..(ni-1)!..*nk!)算出每个数出现在每个位置的次数,然后乘以i加起来就是i元素的贡献值了

转载请注明出处:寻找&星空の孩子

 #include<stdio.h>
#include<string.h>
#define LL unsigned long long int a[];// 题目没有说很清楚,是0-9之间的数;
int b[];
LL jie[];
int N;
void init()
{
jie[]=;
for(LL i=;i<;i++)
{
jie[i]=i*jie[i-];
}
}
LL chsort(LL x)
{
LL cnt=;
for(int i=;i<;i++)
{
if(a[i])
{
if(i==x)
cnt*=jie[a[i]-];
else
cnt*=jie[a[i]];
}
}
return cnt;
}
int main()
{
// freopen("Add.txt","r",stdin); LL ans,sum;
init();
while(scanf("%d",&N),N)
{
sum=;
memset(a,,sizeof(a));
for(int i=;i<N;i++)
{
int tp;
scanf("%d",&tp);
a[tp]++;
// sum+=b[i];
}
ans=;
// ans=jie[N-1]*sum;
for(LL i=;i<;i++)
{
if(a[i])
{
ans+=jie[N-]*i/chsort(i);
}
}
LL kk=;
for(int i=;i<=N;i++)
{
kk=kk*+ans;
}
printf("%llu\n",kk);
}
return ;
}

Add Again(重复元素排序) UVA11076的更多相关文章

  1. 普林斯顿大学算法课 Algorithm Part I Week 3 重复元素排序 - 三路快排 Duplicate Keys

    很多时候排序是为了对数据进行归类,这种排序重复值特别多 通过年龄统计人口 删除邮件列表里的重复邮件 通过大学对求职者进行排序 若使用普通的快排对重复数据进行排序,会造成N^2复杂度,但是归并排序和三路 ...

  2. python 重复元素排序

    def counting_sort(array1, max_val): m = max_val + count = [] * m for a in array1: # count occurences ...

  3. 排序及重复元素去重的说明,TreeSet,HashSet

    先看下面一段代码: package 类集; import java.util.Set; import java.util.TreeSet; class Person{ private String n ...

  4. java8 stream初试,map排序,list去重,统计重复元素个数,获取map的key集合和value集合

    //定义一个100元素的集合,包含A-Z List<String> list = new LinkedList<>(); for (int i =0;i<100;i++) ...

  5. lintcode :Remove Duplicates from Sorted List 删除排序链表中的重复元素

    题目: 删除排序链表中的重复元素 给定一个排序链表,删除所有重复的元素每个元素只留下一个.   您在真实的面试中是否遇到过这个题? 样例 给出1->1->2->null,返回 1-& ...

  6. leetcode-83.删除排序链表中的重复元素

    leetcode-83.删除排序链表中的重复元素 Points 链表 题意 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2 输出: 1- ...

  7. 【leetcode-82,83,26,80】 删除排序链表/数组中的重复元素

    83. 删除排序链表中的重复元素 (1 pass) 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2 输出: 1->2 示例 2: ...

  8. 26. Remove Duplicates from Sorted Array(删除排序数组中的重复元素,利用排序的特性,比较大小)

      Given a sorted array, remove the duplicates in-place such that each element appear only once and r ...

  9. leetcode-217-Contains Duplicate(使用排序来判断整个数组有没有重复元素)

    题目描述: Given an array of integers, find if the array contains any duplicates. Your function should re ...

随机推荐

  1. shiro授权测试

    shiro-permission.ini 创建存放权限的配置文件shiro-permission.ini,如下: [users] #用户zhang的密码是1111111,此用户具有role1和role ...

  2. FFmpeg 学习(三):将 FFmpeg 移植到 Android平台

    首先需要去FFmpeg的官网http://www.ffmpeg.org/去下载FFmpeg的源码,目前的版本号为FFmpeg3.3(Hilbert). 下载的文件为压缩包,解压后得到ffmpeg-3. ...

  3. Mac 系统安装教程

    上周末买了一个二手的Mac,当时是抹掉整个硬盘的,所以只能选择重装系统了.但是,多次重装都是失败了.最后使用USB安装,试了好几次,误打误撞总算成功了. 下面是整个安装的教程: 1. 备份好所有的私人 ...

  4. 12、json、GridView、缓存

    1.解析json数据: public class PhotosData { public int retcode; public PhotosInfo data; public class Photo ...

  5. Java核心技术卷一基础知识-第11章-异常、断言、日志和调试-读书笔记

    第11章 异常.断言.日志和调试 本章内容: * 处理错误 * 捕获异常 * 使用异常机制的技巧 * 使用断言 * 日志 * 调试技巧 * GUI程序排错技巧 * 使用调试器 11.1 处理错误 如果 ...

  6. 使用Consul 实现 MagicOnion(GRpc) 服务注册和发现

    1.下载打开Consul 笔者是windows下面开发的(也可以使用Docker). 官网下载windows的Consul https://www.consul.io/ 使用cmd窗口打开,输入con ...

  7. HTML5之日历控件

    HTML5定义了几个与日期有关的新控件.支持日期控件的浏览器会提供一个方便的下拉式日历,供用户选择. 以下测试和截图都是在谷歌浏览器完成的,其他浏览器可能略有差异. 1.日期时间控件 HTML代码: ...

  8. LabVIEW(六):创建VI

    1.多使用快捷键,可以提高工作效率键盘快捷键 说明对象/动作Shift-单击 选取多个对象:将对象添加到当前选择之中.方向箭头键 将选中的对象每次移动一个像素.Shift-方向箭头键 将选中的对象每次 ...

  9. Tools - 正版Windows7系统的下载与安装

    下载 微软原版系统下载地址:https://msdn.itellyou.cn/ 根据系统类型.语言和版本,下载合适的系统ISO文件. 例如: Windows 7 Professional with S ...

  10. MYSQL服务器系统变量

    一:查看服务所有变量 MySQL服务器维护许多配置其操作的系统变量.每个系统变量都有一个默认值.可以使用命令行或选项文件中的选项在服务器启动时设置系统变量.其中大多数都可以在运行时使用动态更改 SET ...