題目鏈接
題意:給定n個數字,每個數字可以是0-l,要選其中一些數字,然後使得和為k,問方案
思路:狀壓dp,滾動數組,狀態表示第i個數字,能組成的數字狀態為s的狀態,然後每次一個數字,循環枚舉它要選取1 - min(l,k)的多少,然後進行狀態轉移
代碼:
#include#include typedef long long ll; const int N = (1<<20) + 5; const ll MOD = 1000000007; int t, n, k; ll l, dp[N]; int main() { scanf("%d", &t); while (t--) { scanf("%d%d%lld", &n, &k, &l); int s = (1< = 0; i--) { if (dp[i] == 0) continue; ll tmp = yu * dp[i] % MOD; ll now = dp[i]; for (int j = 1; j <= l; j++) { int next = i|((i<