• P1641 [SCOI2010]生成字符串


    算是个裸题吧。

    c(n+m,n)-c(n+m,n+1) 逆元计算,别忘了取模

     1 #include"bits/stdc++.h"
     2 using namespace std;
     3 typedef long long ll;
     4 
     5 const ll mod = 20100403;
     6 
     7 int n,m;
     8 
     9 ll jc[3000000];
    10 
    11 void exgcd(ll a,ll b,ll &x,ll &y)
    12 {
    13    if(!b)
    14    {
    15         x=1,y=0; 
    16         return ;
    17        }    
    18   exgcd(b,a%b,x,y);
    19   ll t=x;
    20   x=y;
    21   y=t-(a/b)*y;
    22   
    23 }
    24 
    25 ll C(ll n,ll m)
    26 {   ll x,y;
    27    exgcd((jc[m]*jc[n-m])%mod,mod,x,y);
    28     return jc[n]*x%mod;
    29 }
    30 int main()
    31 { 
    32   cin>>n>>m;
    33   jc[1]=1;
    34   for (int i=2;i<=n+m;i++)jc[i]=jc[i-1]*i%mod;
    35   cout<<((C(n+m,n)-C(n+m,n+1))%mod+mod)%mod; 
    36    
    37    
    38 }
    39 
    40 
    41 /*
    42 1
    43 2 2
    44 3 5 5
    45 4 9 14 146
    46 5 14 28 42 42
    47 6 20 48 90 132 132
    48 7 27 75 165 297 429 429
    49 8 35 110 275 572 1001 1430 1430
    50 9 44 154 429 1001 2002 3432 4862 2w62
    51 10 54 208 637 1638 3640 7072 11934 16796 16796
    52 11 65 273 910 2548 6188 13260 25194 41990 58786 58786
    53 12 77 350 1260 3808 9996 23256 48450 90440 149226 208012 208012
    54 13 90 440 1700 5508 15504 38760 87210 177650 326876 534888 742900 742900
    55 14 104 544 2244 7752 23256 62016 149226 326876 653752 1188640 1931540 2674440 2674440
    56 15 119 663 2907 10659 33915 95931 245157 572033 1225785 2414425 4345965 7020405 9694845 9694845
    57 16 135 798 3705 14364 48279 144210 389367 961400 2187185 4601610 8947575 15967980 25662825 35357670 35357670
    58 
    59 
    60 */
  • 相关阅读:
    回溯算法(DFS:深度优先)
    KNN原理和实现
    Anaconda虚拟环境控制
    c++容器
    最坏情况为线性时间的选择算法
    JVM原理解析
    substr、substring和slice的区别
    word-wrap与break-word属性的区别
    js修改伪类的值
    快速批量删除文件名中相同的文字
  • 原文地址:https://www.cnblogs.com/zhangbuang/p/10350516.html
Copyright © 2020-2023  润新知