Codeforces512c-pluses everywhere-Simulation/math/permutation combination template

Source: Internet
Author: User

After study, we can find that each person's contribution is C (n-2,k-1) +c (n-3,k-1) ... C (k-1,k-1)

Also note that the plus sign is all on the left.

A template for O (n) preprocessing O (1) combination numbers is also used here. It's wonderful. Wonderful...

1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineLL Long Long5 6 using namespacestd;7 8 Const intMOD = 1e9+7;9 Const intMAXN = 3e5+Ten;Ten  One LL F[MAXN],INV[MAXN],FAC[MAXN]; A  - voidInit () - { thefac[0] = fac[1] = inv[0] = inv[1] = f[0] = f[1] =1; -      for(intI=2; i<maxn;i++) -     { -Fac[i] = fac[i-1]*i%MOD; +LL t = mod/i,k = mod%i; -F[i] = (mod-t) *f[k]%MOD; +Inv[i] = inv[i-1]*f[i]%MOD; A     } at } -  - ll C (ll n,ll m) - { -     if(N < m | | m <0)return 0; -     returnfac[n]*inv[m]%mod*inv[n-m]%MOD; in } -  to CharS[MAXN]; + intn,k; - LL SAVE[MAXN]; the  * intMain () $ {Panax Notoginseng init (); -      while(~SCANF ("%d%d",&n,&K)) the     { +scanf"%s", s); ALLBase=1; the          for(intI=1; i<=n;i++) +         { -Save[i] = (save[i-1]+c (n1-i,k-1)*Base%MOD)%MOD; $             Base=Base*Ten%MOD; $         } -LL ans =0;Base=1; -          for(intj=m-1; i>=0; i--) the         { -Ans + = (s[i]-'0') * (save[n-1-i]+c (i,k) *Base%MOD)%MOD;WuyiAns%=MOD; the             Base=Base*Ten%MOD; -         } Wuprintf"%i64d\n", ans); -     } About}

Codeforces512c-pluses everywhere-Simulation/math/permutation combination template

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.