题目链接

题目叙述很啰嗦,可以简化为: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_A1123#Is It a Complete AVL Tree

    Source: PAT A1123 Is It a Complete AVL Tree (30 分) Description: An AVL tree is a self-balancing bina ...

  2. eas之获取不同类型的组织视图

    OrgViewF7 orgF7=new OrgViewF7(this);orgF7.setCurrentCUID(company.getId().toString());orgF7.setMultiS ...

  3. AtCoder ABC 076D - AtCoder Express

    传送门:http://abc076.contest.atcoder.jp/tasks/abc076_d 本题是一个运动学问题——匀变速运动. 一个质点,从静止开始运动.按照速度限制,可将运动划分成n个 ...

  4. poj 1274 基础二分最大匹配

    #include<stdio.h> #include<string.h> #define N 300 #define inf 0x3fffffff int mark[N],li ...

  5. 【ACM】hdu_zs1_1001_水仙花数_201307271504

    水仙花数 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)Total Submissio ...

  6. js面向对象 多种创建对象方法小结

    转自js面向对象 多种创建对象方法小结 1.对象字面量 var clock={ hour:12, minute:10, second:10, showTime:function(){ alert(th ...

  7. JAVAEE之-----MySQL分页技术(带搜索)

    需求: 为什么须要採用分页技术呢?在数据库中我们查询数据的时候,须要将数据返回到显示页面.数据库中含有大量数据,所有显示在一个页面过于太多,所以我们须要採用分页技术.每一页显示不同数据. 主要解决这个 ...

  8. Leetcode 贪心 Best Time to Buy and Sell Stock

    本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie Best Time to Buy and Sell Stock Total Accepted ...

  9. friend(hdoj 1719)

    Friend Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  10. computed与methods的异同

    在vue.js中,有methods和computed两种方式来动态当作方法来用的 如下: 两种方式在这种情况下的结果是一样的 写法上的区别是computed计算属性的方式在用属性时不用加(),而met ...