Problem Description
We are going to distribute apples to n children. Every child has his/her desired number of apple A1,A2,A3,⋯An , Ai indicates the i-th child’s desired number of apple. Those children should stand in a line randomly before we distribute apples. Assume that the i-th position is occupied by pi−th child, i.e. from left to right the id of the children are p1,p2,p3,⋯pn ,So their desired number of apple are Ap1,Ap2,Ap3,⋯Apn . We will distribute Ap1 apples to the left most child,and for the i-th (i>1)child,if there exists a j which makes j < i and Apj>Api true, we will distribute no apples to him/her,otherwise we will distribute Api apples to him/ner. So for a certain permutation there exist a certain number of apples we should distribute. Now we want to know how many apples we should distribute for all possible permutation.
Note: two permutations are considered different if and only if there exists at least a position in which two children’s desired number of apple are different.
 
Input
Multi test cases,the first line contains an integer T which indicates the number of test cases. Then every case occupies two lines.
For each case, the first line contains an integer n which indicates there are n children.
The second line contain n integers A1,A2,A3,⋯An

indicate n children’s desired number of apple.
[Technique specification]
All numbers are integer
1<=T<=20
1<=n<=100000
1<=Ai<=1000000000

 
Output
For each case,output occupies one line,the output format is Case #x: ans, x is the data number starting from 1,ans is the total number of apple modular 1000000007.
 
Sample Input
2
2
2 3
3
1 1 2
 
Sample Output
Case #1: 8
Case #2: 9

Hint

For the second case, all possible permutation and

corresponding distributed apples are
(1,1,2),4
(1,2,1),3
(2,1,1),2
So the total number of apple is 2+3+4=9

 
Source
 
Recommend
heyang
 
简单题意
给你一堆数字,要计算所有不同排列的权值(两个排列为不一样的排列当且仅当至少有一个位置上的数字不同)
权值的计算方法:对于每个位置上的数字,要是这个数字之前不存在比这个数字大的数字,权值就加上这个数字
胡说题解
先排序,然后我们对于每一种数字,我们枚举有多少个被计算到权值里面,然后排列组合出这种情况的不同排列个数
 #include<cstdio>
#include<algorithm>
using namespace std; const long long p=1e9+;
long long a[],fac[],ans;
int n,t; long long power(long long a,long long b){
if(a<=)return a;
if(b==)return ;
if(b==)return a;
long long tmp=power(a,b>>);
tmp=(tmp*tmp)%p;
if(b&==)tmp=(tmp*a)%p;
return tmp;
} long long C(int m,int n){
if(m==)return ;
if(n<)return ;
long long tmp=(fac[n]*power(fac[m],p-))%p;
tmp=(tmp*power(fac[n-m],p-))%p;
return tmp;
} int main(){
scanf("%d",&t);
int i,j,s,k,l;
fac[]=;
for(i=;i<=;i++)fac[i]=(fac[i-]*i)%p;
for(l=;l<=t;l++){
ans=;
scanf("%d",&n);
for(i=;i<=n;i++)scanf("%I64d",&a[i]);
a[n+]=;
sort(a+,a++n);
s=k=;
long long div=;
for(i=;i<=n;i++){
++k;
if(a[i]!=a[i+]){
long long tmp,ss=;
tmp=(fac[s]*fac[k])%p;
tmp=(tmp*fac[n-s-k])%p;
tmp=(tmp*C(s,n))%p;
for(j=;j<=k;j++)ss+=(((a[i]*j)%p)*C(k-j,n-s-j-))%p;
ss%=p;
ans+=(ss*tmp)%p;
ans%=p;
div=(div*fac[k])%p;
s+=k;
k=;
}
}
ans=(ans*power(div,p-))%p;
printf("Case #%d: %I64d\n",l,ans);
}
return ;
}

AC代码

Apple - Hdu5160的更多相关文章

  1. iOS: 在iPhone和Apple Watch之间共享数据: App Groups

    我们可以在iPhone和Apple Watch间通过app groups来共享数据.方法如下: 首先要在dev center添加一个新的 app group: 接下来创建一个新的single view ...

  2. 一道Apple公司(中国)的面试题目

    Apple在中国(上海)有公司业务,但是感觉主要是做测试工作的部门,主要是保障Apple的产品质量QE.面试的时候,面试官出了一道题目,我貌似曾今开过类似的题目,但是由于当场发挥不佳没有答出来.题目大 ...

  3. apple常用网址

    https://developer.apple.com/ https://itunesconnect.apple.com/ iTunes Connect Developer Guide https:/ ...

  4. Apple Pay 初探

    Apple Pay 一.概述 1.支付方式:Touch ID/ Passcode 2.设备要求:iPhone6以上(iphone:线上/线下 ipad:线上 watch:线下) 3.系统要求:iOS8 ...

  5. Apple、Google、Microsoft的用户体验设计原则

    轻巧的Apple 注重设计过程: 在设计过程中引入用户交互的5个目标: 了解您的目标客户 分析用户的工作流 构造原型系统 观察用户测试 制定观察用户准则 做出设计决定 避免功能泛滥 80% 方案 优秀 ...

  6. 【转】iOS开发 -- Apple Pay

    技术博客原地址:http://www.cnblogs.com/dashunzi/p/ApplePay.html#top 原技术博客中有源码和视频,有感兴趣的朋友可以研究一下! 一.什么是Apple P ...

  7. Apple的LZF算法解析

    有关LZF算法的相关解析文档比较少,但是Apple对LZF的开源,可以让我们对该算法进行一个简单的解析.LZFSE 基于 Lempel-Ziv ,并使用了有限状态熵编码.LZF采用类似lz77和lzs ...

  8. [css]我要用css画幅画(九) - Apple Logo

    接着之前的[css]我要用css画幅画(八) - Hello Kitty,这次画的是苹果公司的logo 这次打算将分析和实现步骤尽量详细的说一说. 其实之前的也打算详细讲分析和设计过程,不过之前的图比 ...

  9. [Erlang 0106] Erlang实现Apple Push Notifications消息推送

        我们的IOS移动应用要实现消息推送,告诉用户有多少条消息未读,类似下图的效果(笑果),特把APNS和Erlang相关解决方案笔记于此备忘.          上面图片中是Apple Notif ...

随机推荐

  1. Updating Homebrew... 长时间不动解决方法

    确保你已安装Homebrew 依次输入下面的命令(注意:不要管重置部分的命令,这里原作者贴出来.我也贴出来是以防需要重置的时候有参考操作命令) 替换brew.git: cd "$(brew ...

  2. Docker介绍及安装

    Docker介绍 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制, ...

  3. yarn 原理

    产生背景 直接源于MRv1在几个方面的缺陷 扩展性受限(NameNode,JobTracker设计为单一节点,内存容量有限) 单点故障 难以支持MR之外的计算 slot数目无法动态修改,Map slo ...

  4. 程序员的冷笑话 python版本

    在伯乐在线上看到了个冷笑话,感觉很有意思. void tellStory() { printf("从前有座山\n"); printf("山上有座庙\n"); p ...

  5. Ubuntu—终端下重启与关机

    重启命令 :         1.shutdown -r now 立刻重启    2.shutdown -r 10 过10分钟自动重启    3.shutdown -r 20:35 在时间为20:35 ...

  6. RDL/RDLC批量单据打印 [转]

    RDL/RDLC批量单据打印 使用RDL或RDLC进行单据打印时,单张单据打印比较直观简单,无需说明.下面我们来谈一下批量单据打印的实现方法.以下以RDL的ReportBuilder设计环境为例进行讲 ...

  7. Java Class Object

    Object类 它是所有类的基类. public class Person { } //实际上是 public class Person extends Object { } Object类的方法 t ...

  8. 用逗号隔开简单数据保存为csv

    用记事本编辑简单数据,用英文逗号隔开,编辑为多列,保存为.csv文件.可以用Excel打开编辑.

  9. java — 值传递和引用传递

    在 Java 应用程序中永远不会传递对象,而只传递对象引用.因此是按引用传递对象.Java 应用程序按引用传递对象这一事实并不意味着 Java 应用程序按引用传递参数.参数可以是对象引用,而 Java ...

  10. lintcode-14-二分查找

    二分查找 给定一个排序的整数数组(升序)和一个要查找的整数target,用O(logn)的时间查找到target第一次出现的下标(从0开始),如果target不存在于数组中,返回-1. 样例 在数组 ...