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