Test Instructions:Link
Method:The number +lucas theorem of solutions for indefinite equations
parsing:After having done so many indefinite equation solutions, each time it is a combination of the number of methods--! This mod is a prime number and observes that n,m may be larger than MoD, so Lucas is naked.
Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N#define MOD 1000000007Using namespace Std;typedefLong LongllintN;ll S;ll F[n]; ll Quick_my (ll x,ll y,ll Mod) {ll ret=1; while(y) {if(y&1) ret= (ret*x)%mod; x= (x*x)%mod; y>>=1; }returnRET;} ll Get_c (ll n,ll m) {if(n<m)return 0;if(m>n-m) m=n-m; ll top=1, bot=1; for(intI=1; i<=m;i++) {top= (top* (n-i+1))%MoD; bot= (bot*i)%MoD; }returnTop*quick_my (bot,MoD-2,MoD)%MoD;} ll Lucas (ll n,ll m) {if(m==0)return 1;returnGet_c (n%MoD, m%MoD) *lucas (n/MoD, m/MoD)%MoD;} ll ans;voidDfsintNowintCnt,llsum){if(now==n+1) {if(S-sum<0)return;if(cnt&1) ans= ((Ans-lucas (S-sum+n-1, N-1))%MoD+MoD)%MoD;ElseAns= (Ans+lucas (S-sum+n-1, N-1))%MoD;return; } DFS (now+1Cntsum); DFS (now+1, cnt+1,sum+f[now]+1);}intMain () {scanf ("%d%lld", &n,&s); for(intI=1; i<=n;i++) scanf ("%lld", &f[i]); Dfs1,0,0); printf"%lld\n", ans);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The number +lucas theorems of solutions of Codeforces #451E Devu and Flowers indefinite equations