N dice. Each dice has k faces and the numbers are 1 ~ K
Q: There are several solutions to add the Top n digits of n dice to S.
We can think of such a DP.
Dp [I] [j] indicates the sum of the first I dice and the total number of solutions when the sum is less than or equal to j. This can be done during the transfer.
Dp [I + 1] [j] = dp [I + 1] [J-1] + (dp [I] [J-1]-dp [I] [j-k-1]) (j-k-1> = 0, otherwise it is 0)
Dp [I + 1] [J-1] is less than the total number of j solutions, followed by this is naturally equal to the total number of j solutions because the first I dice Composition
J-k ~ The number between the J-1 can be combined by the number of I + 1 dice to Form j, so should add the following difference
Okay. Now that all the data has been designed, let's write it. But let's take a look at the data range --!, N = 1000, S = 15000,
After two seconds, the time is enough, and the space is stuck,
Think about it, the status of the current layer only needs the status of the previous layer.
The previous status does not need to be saved, so use a scroll space to save it.
[Cpp]
# Include <cstdio>
# Include <cstring>
Typedef long lld;
Const fig mod = 100000007;
Const int maxn = 15010;
Lld dp [2] [maxn];
Int n, k, s;
Lld get (int a, int l, int r)
{
Lld x = 0;
L-= 1;
If (l> = 0) x = dp [a] [l];
Lld y = dp [a] [r];
Return y-x;
}
Lld solve ()
{
Memset (dp, 0, sizeof (dp ));
Int a = 0, B = 1;
For (int I = 0; I <= s; I ++) dp [a] [I] = 1;
For (int I = 0; I <n; I ++)
{
Dp [B] [0] = 0;
For (int j = 1; j <= s; j ++)
{
Dp [B] [j] = dp [B] [J-1] + get (a, j-k, J-1 );
Dp [B] [j] % = mod;
}
A ^ = 1;
B ^ = 1;
}
Return (get (a, s, s) % mod + mod) % mod;
}
Int main ()
{
Int t, ca = 1;
Scanf ("% d", & t );
While (t --)
{
Scanf ("% d", & n, & k, & s );
Printf ("Case % d: % lld \ n", ca ++, solve ());
}
Return 0;
}
Author: haha593572013