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月18日)

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

  2. vim中project多标签和多窗口的使用

    1.打开多个窗口 打开多个窗口的命令以下几个: 横向切割窗口 :new+窗口名(保存后就是文件名) :split+窗口名,也可以简写为:sp+窗口名 纵向切割窗口名 :vsplit+窗口名,也可以简写 ...

  3. 【JUC源码解析】AQS

    简介 AQS,也即AbstractQueuedSynchronizer,抽象队列同步器,提供了一个框架,可以依赖它实现阻塞锁和相关同步器.有两种类型,独占式(Exclusive)和共享式(Share) ...

  4. Bing wallpaper api

    list: http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-cn idx:-1为明天,1为 ...

  5. c# enum 解析

    解析定义的枚举 public enum OrderPaymentStatus { /// <summary> /// 未支付 /// </summary> [Descripti ...

  6. Python3.6+selenium3.8+Firefox5.7 环境搭建

    大家好,我是阿哲,本人是从php转岗过来学习测试的一名小菜! 在学习selenium过程中,发现运行selenium有很多的问题. 我们在利用pip install selenium 安装的最新版后, ...

  7. javac 编译过程

    javac 编译过程     一.解析与填充符号表: 1.  语法.此法分析:          a) 语法分析:将源代码字符流转换为标记(Token:编译过程最小元素)集合.          b) ...

  8. Python 作用域和命名空间

    在介绍类之前,我首先要告诉你一些Python的作用域规则.类定义对命名空间有一些巧妙的技巧,你需要知道作用域和命名空间如何工作才能完全理解正在发生的事情.顺便说一下,关于这个主题的知识对任何高级Pyt ...

  9. Vue 编程之路(三)—— Vue 中子组件在父组件的 v-for 循环里,父组件如何调取子组件的事件

    (标题的解决方案在第二部分) 最近公司的一个项目中使用 Vue 2.0 + element UI 实现一个后台管理系统的前端部分,属于商城类型. 一.前期思路: 其中在“所有订单”页面,UI 给的设计 ...

  10. yun rpm

    RPM:RedHat Package Manager的简称,是一种数据库记录的方式的管理机制.当需要安装的软件的依赖软件都已经安装,则继续安装,否则不予安装. 特点:1.已经编译并打包完成2.软件的信 ...