**题意:**按要求完成n个任务,每个任务必须进行a[i]次才算完成,且按要求,第i个任务必须在大于i任务完成之前完成,问有多少种完成顺序的组合。(n

/** @Date    : 2016-11-21-18.26

* @Author : Lweleth (SoungEarlf@gmail.com)

* @Link : https://github.com/

* @Version :

*/

#include <stdio.h>

#include <iostream>

#include <string.h>

#include <algorithm>

#include <utility>

#include <vector>

#include <map>

#include <set>

#include <string>

#include <stack>

#include <queue>

//#include<bits/stdc++.h>

#define LL long long

#define MMF(x) memset((x),0,sizeof(x))

#define MMI(x) memset((x), INF, sizeof(x))

using namespace std;



const int INF = 0x3f3f3f3f;

const int N = 1e5+20;

const LL mod = 1000000007;



LL inv[N*10], fa[N*10];



LL fpow(LL a, int n)

{

LL r = 1;

while(n > 0)

{

if(n & 1)

r = r * a % mod;

a = a * a % mod;

n >>= 1;

}

return r;

}

void init()

{

fa[0] = 1;

inv[0] = 1;

for(LL i = 1; i <= 1000100; i++)

{

fa[i] = fa[i-1] * i % mod;

inv[i] = fpow(fa[i], mod - 2);

}

}



LL C(LL n, LL m)

{

if(m > n)

return 0;

LL ans = 0;

ans = ((fa[n] * inv[m] % mod)* inv[n-m]) % mod;

return ans;

}



LL lucas(LL n, LL m)

{

if(m == 0)

return 1;

return C(n % mod, m % mod) * lucas(n / mod, m / mod) % mod;

}

LL a[1100];

int main()

{

int T;

cin >> T;

init();

int cnt = 0;

while(T--)

{

LL n;

scanf("%lld", &n);

for(int i = 1; i <= n; i++)

scanf("%lld", a + i);

LL ans = 1;

LL ct = 0;

for(int i = 1; i <= n; i++)

{

ct += a[i];

ans = (ans*lucas(ct-1, a[i]-1) % mod);

}

printf("Case %d: %lld\n", ++cnt, ans);

}

return 0;

}


LightOJ 1226 - One Unit Machine Lucas/组合数取模的更多相关文章

  1. BZOJ_2142_礼物_扩展lucas+组合数取模+CRT

    BZOJ_2142_礼物_扩展lucas+组合数取模 Description 一年一度的圣诞节快要来到了.每年的圣诞节小E都会收到许多礼物,当然他也会送出许多礼物.不同的人物在小E 心目中的重要性不同 ...

  2. LightOJ - 1226 - One Unit Machine(排列组合)

    链接: https://vjudge.net/problem/LightOJ-1226 题意: OUM is a one unit machine which processes jobs. Sinc ...

  3. lightoj 1226 - One Unit Machine(dp+大组合数去摸)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1226 题解:由于这些任务完成是有先后的所以最后一个完成的肯定是最后一个任务的子 ...

  4. 1226 - One Unit Machine

    1226 - One Unit Machine   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB ...

  5. 组合数取模Lucas定理及快速幂取模

    组合数取模就是求的值,根据,和的取值范围不同,采取的方法也不一样. 下面,我们来看常见的两种取值情况(m.n在64位整数型范围内) (1)  , 此时较简单,在O(n2)可承受的情况下组合数的计算可以 ...

  6. hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)

    DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...

  7. lucas定理解决大组合数取模

    LL MyPow(LL a, LL b) { LL ret = ; while (b) { ) ret = ret * a % MOD; a = a * a % MOD; b >>= ; ...

  8. 2015 ICL, Finals, Div. 1 Ceizenpok’s formula(组合数取模,扩展lucas定理)

    J. Ceizenpok’s formula time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. 组合数取模&&Lucas定理题集

    题集链接: https://cn.vjudge.net/contest/231988 解题之前请先了解组合数取模和Lucas定理 A : FZU-2020  输出组合数C(n, m) mod p (1 ...

随机推荐

  1. Hybrid APP基础篇(五)->JSBridge实现示例

    说明 JSBridge实现示例 目录 前言 参考来源 楔子 JS实现部分 说明 实现 Android实现部分 说明 JSBridge类 实现 Callback类 实现 Webview容器关键代码 实现 ...

  2. 【备忘】mysql常用操作汇总

    1.增删改查 // 插入一条数据 insert into tableName values('liu','bei') // 删除一条数据 delete from tableName where las ...

  3. Microsoft Edge goes Chromium

    Microsoft Edge goes Chromium https://techcrunch.com/2018/12/06/microsoft-edge-goes-chromium-and-maco ...

  4. BZOJ4813 CQOI2017小Q的棋盘(树形dp)

    设f[i][j]为由i号点开始在子树内走j步最多能经过多少格点,g[i][j]为由i号点开始在子树内走j步且回到i最多能经过多少格点,转移显然. #include<iostream> #i ...

  5. NAT穿透(UDP打洞)

    1.NAT(Network Address Translator)介绍 NAT有两大类,基本NAT和NAPT. 1.1.基本NAT 静态NAT:一个公网IP对应一个内部IP,一对一转换 动态NAT:N ...

  6. CentOS 不间断会话(ssh关闭后如何保证程序继续运行)(nohup和screen)

    当使用ssh与远程主机的会话被关闭时,在远程主机上运行的命令也随之被中断. 就是ssh 打开以后,bash等都是他的子程序,一旦ssh关闭,系统将所有相关进程杀掉!! 导致一旦ssh关闭,执行中的任务 ...

  7. 【题解】51nod 1806 wangyurzee的树

    看这道题目懵逼了好久, \(m <= 17\) 一眼容斥,然而并没有想到怎么求出生成树的个数.然后灵光一闪——我不是学过一个叫Prüfer编码的东西嘛?!那就完美解决啦~ Prüfer编码就是将 ...

  8. [bzoj3712][PA2014]Fiolki

    description 题面 data range \[ 0\le m<n\le 200000,0\le k\le 500000\] solution 之前本人一直煞笔地思考暴力是否可行 考虑按 ...

  9. [LOJ2540] [PKUWC2018] 随机算法

    题目链接 LOJ:https://loj.ac/problem/2540 Solution 写的时候脑子不太清醒码了好长然后时间\(LOJ\)垫底... 反正随便状压\(dp\)一下就好了,设\(f[ ...

  10. [luogu2783] 有机化学之神偶尔会做作弊

    题目链接 洛谷. Solution 边双缩点然后\(lca\)跑\(dis\)就好了. 注意这里是边双,不知道为啥所有题解都说的是点双. 边双是定义在点上的,即每个点只属于一个边双:点双是定义在边上的 ...