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. Aop实现拦截方法参数

    对于spring框架来说,最重要的两大特性就是AOP 和IOC. 以前一直都知道有这两个东西,在平时做的项目中也常常会涉及到这两块,像spring的事务管理什么的,在看了些源码后,才知道原来事务管理也 ...

  2. Fiddler - 拦截手机请求

    1. 在电脑上安装Fillder. 安装好之后的Fiddler 打开是这样的: 2. 浏览器访问http://127.0.0.1:8888/fiddler,下载证书并安装 3. 打开抓取https请求 ...

  3. Charles使用及mock数据

    1.下载charles 3.9.2[破解版地址:https://download.csdn.net/my] 下方有一种方法可破解4.2以前的版本 // Charles Proxy License // ...

  4. 微信小程序之注释出现的问题(.json不能注释)

    js的注释一般是双斜杠// 或者是/**/这样的快注释 .json是配置文件,其内容必须符合json格式内部不允许有注释. JSON有两种数据结构: 名称/值对的集合:key : value样式: 值 ...

  5. 初涉 JavaScript

    网页是什么 网页 = Html+CSS+JavaScriptHtml:网页元素内容CSS:控制网页样式JavaScript:操作网页内容,实现功能或者效果 JavaScirpt 发展历史 参考 使用 ...

  6. C二维数组行为空,列不为空

    二维数组: 处理二维数组得函数有一处可能不太容易理解:数组的行可以在函数调用时传递,但是数组的列却只能被预置在函数内部. eg: #define COLS 4 int sum(int ar[][COL ...

  7. 机器学习之支持向量机(Support Vector Machine)

    转载请注明出处:http://www.cnblogs.com/Peyton-Li/ 支持向量机 支持向量机(support vector machines,SVMs)是一种二类分类模型.它的基本模型是 ...

  8. df -h 卡住

    mount 检查是否有挂载nfs的分区       网络挂载     如果有请umount  -l   /相应目录      umount -l  10.74.82.205:/letv/fet/nfs ...

  9. iOS- 用MapKit和CoreLocation 来实现移动设备(地图与定位)

    1.前言 发现在很多的社交软件都引入了地图和定位功能,如果我们要想实现这两大功能,需要利用到两个框架:MapKit和CoreLocation   我们先来看看CoreLocation框架:   它可以 ...

  10. iOS开发跳转指定页面

    for (UIViewController *VC in self.navigationController.viewControllers) { if ([VC isKindOfClass:[Car ...