某几个值<=20 极可能是状态压缩到一个int中,表示该情况已经被选择
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int N=1<<20,MOD=1e9+7;
int dp[N+10];//状态s表示能产生的 和的集合(1-K) 的情况数
int main(){
int tt; cin>>tt;
while(tt--){
int n,K,L;
cin>>n>>K>>L;
memset(dp,0,sizeof dp);
dp[0]=1;
int duo=0;
if(L>K){
duo=L-K;
L=K;
}
int S=1<<K;
for(int i=0;i<n;i++){//第i个数
for(int s=S-1;s>=0;s--){//和的集合为s,防覆盖
if(dp[s]==0) continue;
//0 + 1-K + K+1-L
int tmp=dp[s];//可能被覆盖ns=s
dp[s]=0;
for(int j=1;j<=L;j++){//枚举第i个数是j
int add=(s<<j)&(S-1);//1-K add j
int ns=s | (1<<(j-1)) | add;
dp[ns]=(dp[ns]+tmp)%MOD;
}
int zero=((LL)tmp*(duo+1))%MOD;//一定不选的部分
dp[s]=(dp[s] + zero)%MOD;
}
}
int ans=0;
for(int s=0;s<S;s++){//sum=K存在
//printf("%d--\n",dp[s]);
if(s&(1<<(K-1)))
ans=(ans+dp[s])%MOD;
}
printf("%d\n",ans);
}
return 0;
}
/*
n个数,子序列的和为k,序列中的数<=L,求这样序列的个数
n,k<=20
dp[s]表示和的集合为s(1-K)的情况数
*/