Test instructions: Constructs n number this n number value range 0-l, this n number exists to take some number of sum equal to K, this is called a method. For a given n,k,l, the number of solutions.
Idea: Load each 1th to indicate whether such a scheme can constitute 1 (1 means can 0 means not) 2nd to indicate can constitute 2 ... This use D[1<<n] DP like backpack back n times can be the last state of the K-bit 1 can be added to the number of methods.
#include <cstring>#include<cstdio>#include<cmath>#include<iostream>#include<algorithm>#defineLL Long Long#defineMOD 1000000007#defineDebug (x) printf (#x "=%d\n", X);using namespacestd;intd[(1<< -)+ -];intMain () {inttt,n,k,l; scanf ("%d",&TT); while(tt--) {scanf ("%d%d%d",&n,&k,&L); memset (d,0,sizeof(d)); d[0]=1; intW= (1<<K)-1; inttot=0; if(l>k) {tot=l-K; L=K; } while(n--) { for(inti=w;i>=0;--i) {if(d[i]==0)Continue; intnow=D[i]; LL tmp= (LL) tot*d[i])%MOD; for(intj=1; j<=l;++j) {intsta=i| (1<< (J-1))| ((I<<J) &W); D[sta]+=Now ; if(D[sta]>mod) d[sta]-=MOD; } D[i]+=tmp; if(D[i]>mod) d[i]-=MOD; } } intans=0; for(intI=0; i<=w;++i)if(I>> (K-1)) &1) {ans+=D[i]; if(ans>MOD) ans-=MOD; } printf ("%d\n", ans); }}