题目链接

题目叙述很啰嗦,可以简化为:n个球[1-1e5],放到m个不同的桶里,一共多少种不同的放法。【桶里可以不放】

------------------------------------------------------------------------------------------------

解C(n+m-1, m-1)

由于m,n可能很大,所以需要用逆元。扩展欧几里得。

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
typedef long long LL;
using namespace std;
const int N = ;
LL MOD = 1e9 + ;
LL F[N], Inv[N]; LL exgcd(LL a, LL b, LL& x, LL& y){
if (b == ){
x = , y = ; return a;
}
else{
auto gcd = exgcd(b, a%b, y, x);
y -= (a / b) * x;
return gcd;
}
} int main(){
LL n, k; cin >> n >> k;
int left = n - k, last = MOD, seg = ;
n += MOD;
for (int i = ; i < left; ++i){
int val; scanf("%d", &val);
if (val>last){
last = val;
}
else{
++seg;
n -= last;
last = val;
}
} n -= last; if (n < ){
puts("No");
}
else{
F[] = ; for (int i = ; i < N; ++i){
F[i] = (i * F[i - ]) % MOD;
}
LL nouse; exgcd(F[N - ], MOD, Inv[N-], nouse);
while (Inv[N - ] < ) Inv[N - ] += MOD; for (int i = N - ; i; --i){
Inv[i] = (Inv[i + ] * (i + )) % MOD;
} std::cout << (F[n + seg - ] * Inv[n]) % MOD*Inv[seg - ] % MOD << std::endl;
//C(n+seg-1,seg-1);
}
}

hiho1804 - 整数分解、组合数、乘法逆元的更多相关文章

  1. hdu5698瞬间移动-(杨辉三角+组合数+乘法逆元)

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  2. (light oj 1102) Problem Makes Problem (组合数 + 乘法逆元)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1102 As I am fond of making easier problems, ...

  3. CodeForces 300C Beautiful Numbers(乘法逆元/费马小定理+组合数公式+高速幂)

    C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. 【板子】gcd、exgcd、乘法逆元、快速幂、快速乘、筛素数、快速求逆元、组合数

    1.gcd int gcd(int a,int b){ return b?gcd(b,a%b):a; } 2.扩展gcd )extend great common divisor ll exgcd(l ...

  5. 【数论】【组合数】【快速幂】【乘法逆元】洛谷 P2265 路边的水沟

    从左上角到右下角,共经过n+m个节点,从其中选择n各节点向右(或者m各节点向下),所以答案就是C(n+m,n)或者C(n+m,m),组合数暴力算即可,但是要取模,所以用了乘法逆元. #include& ...

  6. 题解报告:hdu 1576 A/B(exgcd、乘法逆元+整数快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n ...

  7. HDU 5407(2015多校10)-CRB and Candies(组合数最小公倍数+乘法逆元)

    题目地址:pid=5407">HDU 5407 题意:CRB有n颗不同的糖果,如今他要吃掉k颗(0<=k<=n),问k取0~n的方案数的最小公倍数是多少. 思路:首先做这道 ...

  8. 【模板】求1~n的整数的乘法逆元

    洛谷3811 先用n!p-2求出n!的乘法逆元 因为有(i-1)!-1=i!-1*i (mod p),于是我们可以O(n)求出i!-1 再用i!-1*(i-1)!=i-1 (mod p)即是答案 #i ...

  9. HDU 1452 (约数和+乘法逆元)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1452 题目大意:求2004^X所有约数和,结果mod 29. 解题思路: ①整数唯一分解定理: 一个 ...

随机推荐

  1. PAT_A1115#Counting Nodes in a BST

    Source: PAT A1115 Counting Nodes in a BST (30 分) Description: A Binary Search Tree (BST) is recursiv ...

  2. php第九节课

    面向对象 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  3. python3使用465端口发送邮件来解决阿里云封闭25端口问题

    import smtplibfrom email.mime.text import MIMETextfrom email.utils import formataddr #发件人邮箱账号my_send ...

  4. Running to the End(Codeforces & AtCoder 百套计划)

    ...Reserved for the future... 仿照xxy dalao的CF&CC百套计划,做了一个Codeforces & AtCoder 百套计划,按这个速度刷下去,每 ...

  5. [tyvj1935 Poetize3]导弹防御塔 (二分图多重匹配)

    传送门 Description Freda控制着N座可以发射导弹的防御塔.每座塔都有足够数量的导弹,但是每座塔每次只能发射一枚.在发射导弹时,导弹需要T1秒才能从防御塔中射出,而在发射导弹后,发射这枚 ...

  6. CSS学习笔记之基本介绍

    1.简介 层叠样式表(Cascading Style Sheets,CSS)允许我们把样式设置存储在文件中,从而将内容与表现分离 当同一个 HTML 元素被不只一个样式定义时,最终的样式确定顺序如下( ...

  7. 1069. The Black Hole of Numbers

    For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...

  8. tp5 异常处理

    === <?php/** * Created by PhpStorm. * User: 14155 * Date: 2018/11/10 * Time: 0:26 */ namespace ap ...

  9. Linux黑洞

    1 什么是Linux黑洞 在Linux系统中,/dev/null是一个虚设的设备.俗称"Linux黑洞". 不论什么对/dev/null的写入都会成功.但数据会消失得无影无踪.没有 ...

  10. JavaScript 和Ajax跨域问题

    json格式: { "message":"获取成功", "state":"1", "result": ...