Persona5
Persona5 is a famous video game.
In the game, you are going to build relationship with your friends.
You have NN friends and each friends have his upper bound of relationship with you. Let's consider the i^{th}ith friend has the upper bound U_iUi. At the beginning, the relationship with others are zero. In the game, each day you can select one person and increase the relationship with him by one. Notice that you can't select the person whose relationship with you has already reach its upper bound. If your relationship with others all reach the upper bound, the game ends.
It's obvious that the game will end at a fixed day regardless your everyday choices. Please calculate how many kinds of ways to end the game. Two ways are said to be different if and only if there exists one day you select the different friend in the two ways.
As the answer may be very large, you should output the answer mod 10000000071000000007
Input Format
The input file contains several test cases, each of them as described below.
- The first line of the input contains one integers NN (1 \le N \le 1000000)(1≤N≤1000000), giving the number of friends you have.
- The second line contains NN integers. The i^{th}ith integer represents U_iUi ( 1 \le U_i \le 1000000)(1≤Ui≤1000000), which means the upper bound with i^{th}ith friend. It's guarantee that the sum of U_iUi is no more than 10000001000000.
There are no more than 1010 test cases.
Output Format
One line per case, an integer indicates the answer mod 10000000071000000007.
样例输入
3 1 1 1 3 1 2 3
样例输出
6 60
题目来源
The 2018 ACM-ICPC China JiangSu Provincial Programming Contest
一个人一个人的安排,组合数问题 如 : 1 2 3 C(6,3)* C(3,2)=60
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <vector> 6 #include <queue> 7 #include <stack> 8 #include <cstdlib> 9 #include <iomanip> 10 #include <cmath> 11 #include <cassert> 12 #include <ctime> 13 #include <map> 14 #include <set> 15 using namespace std; 16 typedef long long ll; 17 const ll mod=1e9+7; 18 int n; 19 const int N=1e6+9; 20 ll a[N],sum[N],f[N]; 21 ll mul1(ll a,ll b){ 22 a%=mod;b%=mod; 23 return a*b%mod; 24 } 25 ll mul2(ll a,ll b ,ll c){ 26 a%=mod;b%=mod;c%=mod; 27 return a*b%mod*c%mod; 28 } 29 void egcd(ll a,ll b,ll &x,ll&y){ 30 ll d=a; 31 if(!b){ 32 x=1;y=0; 33 return ; 34 } 35 else{ 36 egcd(b,a%b,y,x); 37 y-=(a/b)*x; 38 } 39 // return d; 40 } 41 ll inv(ll n){ 42 ll x,y; 43 egcd(n,mod,x,y); 44 return (x%mod+mod)%mod; 45 } 46 void init() 47 { 48 f[0]=1; 49 for(int i=1;i<=1000000;i++){ 50 f[i]=(f[i-1]*i)%mod; 51 } 52 } 53 int main() 54 { init(); 55 while(~scanf("%d",&n)){ 56 memset(sum,0,sizeof(sum)); 57 for(int i=1;i<=n;i++){ 58 scanf("%lld",&a[i]); 59 sum[i]=sum[i-1]+a[i]; 60 } 61 ll ans=1; 62 for(int i=n;i>1;i--){ 63 //ans=(ans*f[sum[i]]%mod*inv(f[a[i]])%mod*inv[f[sum[i-1]]%mod)%mod; 64 ans=(ans*mul2(f[sum[i]],inv(f[a[i]]),inv(f[sum[i-1]])))%mod; 65 } 66 printf("%lld\n",ans); 67 } 68 return 0; 69 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现