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优步司机奖励政策 (12月28日-1月3日)

    本周已经公开奖励整的城市有:北 京.成 都.重 庆.上 海.深 圳.长 沙.佛 山.广 州.苏 州.杭 州.南 京.宁 波.青 岛.天 津.西 安.武 汉.厦 门,可按CTRL+F,搜城市名快速查找. ...

  2. 佛山Uber优步司机奖励政策(12月28日到1月3日)

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

  3. Android stdio build.gradle buildscript 里面的repositories 和allprojects里面 repositories 的区别

    第一段 buildscript 里面的 repositories 表示只有编译工具才会用这个仓库. 比如 buildscript 里面的 dependencies classpath 'com.and ...

  4. DSP5509之采样定理

    1. 在实际种信号是模拟连续的,但是AD采样确实离散的数字的,根据采样定理,采样频率要是模拟信号的频率2倍以上采样到的值才没问题. 2. 打开工程 unsigned ]; main() { int i ...

  5. Tomcat - 远程调试配置

    复制一份startup.bat,更名为“startup-debug”. 替换内容如下: call "%EXECUTABLE%" start %CMD_LINE_ARGS% 替换为 ...

  6. MongoDB 安装 增删改查

    MongoDB   一 介绍 1.高性能的数据存储解决方案是大多数大型Web应用程序和服务的核心.后端数据库负责存储一切东西,从用户账户的信息到购物车中的商品,以及博客和评论数据等.好的Web应用需要 ...

  7. C++ 基础面试题-1

    请说出下面代码在32位系统下的输出内容 /* ** 2018/03/21 21:43:00 ** Brief: ** Author:ZhangJianWei ** Email:Dream_Dog@16 ...

  8. Selenium安装(二)

    安装python 安装Selenium之前首先来说一下Python,python是一门动态性语言,python的编写比较灵活,简洁,开发效率高.因此以python结合selenium来进行自动化测试. ...

  9. Selenium 入门到精通系列:三

    Selenium 入门到精通系列 PS:Driver_Element 常用方法 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2 ...

  10. Unity Android设备的输入

    Unity Android设备的输入 1依据屏幕位置输入 有的时候也许是为了整个有些风格的干净,减少屏幕上的UI图标,以至于摒弃了虚拟按键这种常用的输入方式.为了替代虚拟按键的输入方式而选择了依据点击 ...