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

  1.  

1332

444


Problemsetter: Md. Kamruzzaman

Special Thanks: Shahriar Manzoor

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

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

  1. #include<stdio.h>
  2. #include<string.h>
  3. #define LL unsigned long long
  4.  
  5. int a[];// 题目没有说很清楚,是0-9之间的数;
  6. int b[];
  7. LL jie[];
  8. int N;
  9. void init()
  10. {
  11. jie[]=;
  12. for(LL i=;i<;i++)
  13. {
  14. jie[i]=i*jie[i-];
  15. }
  16. }
  17. LL chsort(LL x)
  18. {
  19. LL cnt=;
  20. for(int i=;i<;i++)
  21. {
  22. if(a[i])
  23. {
  24. if(i==x)
  25. cnt*=jie[a[i]-];
  26. else
  27. cnt*=jie[a[i]];
  28. }
  29. }
  30. return cnt;
  31. }
  32. int main()
  33. {
  34. // freopen("Add.txt","r",stdin);
  35.  
  36. LL ans,sum;
  37. init();
  38. while(scanf("%d",&N),N)
  39. {
  40. sum=;
  41. memset(a,,sizeof(a));
  42. for(int i=;i<N;i++)
  43. {
  44. int tp;
  45. scanf("%d",&tp);
  46. a[tp]++;
  47. // sum+=b[i];
  48. }
  49. ans=;
  50. // ans=jie[N-1]*sum;
  51. for(LL i=;i<;i++)
  52. {
  53. if(a[i])
  54. {
  55. ans+=jie[N-]*i/chsort(i);
  56. }
  57. }
  58. LL kk=;
  59. for(int i=;i<=N;i++)
  60. {
  61. kk=kk*+ans;
  62. }
  63. printf("%llu\n",kk);
  64. }
  65. return ;
  66. }

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. 设置HttponlyCookie解决mshtml编程无法获取验证码图片流

    最近给客户做的项目有一个新需求,客户需要在打开的IE浏览器中做自动登录,登录的页面上有神兽验证码.解决验证码的方案是找第三方平台打码.这样就有一个问题,如何把正确的验证码传给第三方打码平台. 大家都知 ...

  2. ScrollView嵌套子View的getDrawingCache为空的解决方法

    ScrollView嵌套子View的getDrawingCache为空的解决方法 问题 将组件的显示布局改为可以滚动的,然后用ScrollView作为了View的父类,发现View的getDrawin ...

  3. clion打断点不生效

    打开CLion的偏好设置(Preferences),选择Build,Execution,Deployment->Toolchains,将Debugger中的Bundled LLDB修改为Bund ...

  4. Python学习笔记【第十篇】:Python面向对象进阶

    保护对象的属性 如果有一个对象,当需要对其进行修改属性时,有2种方法 对象名.属性名 = 数据 ---->直接修改 对象名.方法名() ---->间接修改 为了更好的保存属性安全,即不能随 ...

  5. 部署 HTTPS 访问 ( https:// )

    简单来说,HTTPS协议是由SSL+HTTP协议构建的可进行加密传输.身份认证的网络协议,要比http协议安全. http和https使用的是完全不同的连接方式,用的端口也不一样,前者是80,后者是4 ...

  6. JDK,JRE,JVM,JMM关系与区别

    JVM: Java Virtual Machine, 将java文件编译成class文件并运行class文件的软件 JRE:Java  Runtime  Enviromental,包含了JVM和Jav ...

  7. Parquet 格式文件,查看Schema

    需要社区工具:parquet-tools-1.6.0rc3-SNAPSHOT.jar                  git project: https://github.com/apache/p ...

  8. jvm的那些设置参数你都知道吗

    前言 大家都知道,jvm在启动的时候,会执行默认的一些参数.一般情况下,这些设置的默认参数应对一些平常的项目也够用了.但是如果项目特别大了,需要增加一下堆内存的大小.或者是系统老是莫明的挂掉,想查看下 ...

  9. PHP接口的思考

    其中就有一个SPL(标准PHP库)的尝试,SPL中实现一些接口,其中最主要的就是Iterator迭代器接口,通过实现这个接口,就能使对象能够用于foreach结构,从而在使用形式上比较统一.比如SPL ...

  10. .NET CoreCLR 源码调试

    https://github.com/dotnet/coreclr/blob/master/Documentation/building/windows-instructions.md https:/ ...