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. 成都Uber优步司机奖励政策(1月28日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  2. CakePHP中回调函数的使用

    我们知道模型主要是用来处理数据的,有时我们想在模型操作之前或之后做一些额外逻辑处理,这时候就可以使用回调函数. 回调函数有很多种,beforeFind,afterFind,beforeValidate ...

  3. jmeter的脚本增强之参数化

    jmeter作为一款开源的测试工具,功能广泛,深受测试同胞们的喜爱,这次来讲讲关于如何参数化及其方式.那为什么要进行一个参数化呢,如做压测时,要有大量的数据来模拟用户的真实场景,像登录页面操作,系统是 ...

  4. 使用postman实现半自动化

    前些日子项目要上一个活动,其中有一个功能是幸运大转盘,用户可以随机抽奖,奖品有多种满减券及多种商品,但是奖品都是有抽中概率的,且有的商品还设置有库存,所以测试点便是测试抽奖的概率和库存.接下来拆分一下 ...

  5. C 数据类型 常量 变量

    一 数据类型 1. 什么是数据 生活中时时刻刻都在跟数据打交道 比如体重数据 血压数据 股价数据等 在我们使用计算机的过程中 会接触到各种各样的数据 有文档数据 图片数据 视频数据 还有聊QQ时产生的 ...

  6. JAVA基础学习之路(五)数组的定义及使用

    什么是数组:就是一堆相同类型的数据放一堆(一组相关变量的集合) 定义语法: 1.声明并开辟数组 数据类型 数组名[] = new 数据类型[长度]: 2.分布完成 声明数组:数据类型 数组名 [] = ...

  7. [转载]CENTOS 6.0 iptables 开放端口80 3306 22端口

    原文地址:6.0 iptables 开放端口80 3306 22端口">CENTOS 6.0 iptables 开放端口80 3306 22端口作者:云淡风轻 #/sbin/iptab ...

  8. 使用bing或google来翻译网页

    google代码:在</head>之后插入 <meta name="google-translate-customization" content="4 ...

  9. 259 [LeetCode] 3Sum Smaller 三数之和较小值

    题目: Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 ...

  10. Simple Pipelined Function

    SELECT * FROM TABLE(PKG_TEST.FN_DIC_DB_TAB) CREATE OR REPLACE PACKAGE PKG_TEST IS   TYPE OBJ_DICDB_R ...