The number +lucas theorems of solutions of Codeforces #451E Devu and Flowers indefinite equations

Source: Internet
Author: User

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

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.