Test instructions
Give an n number of columns, and take some numbers to form a new series,
If there are some numbers in the new series and K, then this is a good sequence, ask the number of such a series.
N,k<=20, A[i] <=l
Status: Dp[][state] The binary of state in each representation and for (1~k), 1 means it can be taken, and 0 means that it cannot be taken.
State transfer equation:dp[i][state] = SUM (dp[i-1][state ']); State = 1<< (p-1) | | State ' | | (State ' <<p) &size); 1<=p<=min (k,l); Size= (1<<k)-1;
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;typedef long LL; Const LL mod = 1e9 + 7; LL Dp[1<<22];int Main () {int T, n, K, L; scanf ("%d", &t); while (t--) {scanf ("%d%d%d", &n, &k, &l); int min = min (L, k); int SIZE = (1<<k)-1; memset (DP, 0, sizeof DP); Dp[0] = 1; for (int i=0, i<n; ++i) {for (int j=size; j>=0;--j) if (dp[j]>0) {LL TMP = Dp[j]; for (int p=1; p<=min; ++p) {int next= (1<< (p-1)) |j| ( (j<<p) &size); Plus P itself this number + originally desirable number + the number of the original desirable to add p after the number, that is composed of all plus p after the case Dp[next] =dp[next] + tmp; if (dp[next]>mod) dp[next]-= mod; {Dp[j] = Dp[j] + (LL) tmp* (l-k) if (k<l)//Number of I is selected greater than K: if (Dp[j]>mod) dp[j]-= mod; }}} LL ans = 0; for (int i=0; i<=size; ++i) if (i& (1<< (k-1))) {ans = ans + dp[i]; if (ans>mod) ans-= mod; } printf ("%i64d\n", ans); } return 0;}