James's dice Time Limit: 1000 ms memory limit: 65536 k any questions? Click Here ^_^ As we all know, James is fond of playing dice. One day, Xiao Fang asked Xiao 1 a question. How many results can I throw n dice at a time? James didn't want Xiao Fang to think he couldn't answer the question, so he turned to you for help. You must help James. Enter an integer t to indicate that there are T groups of data. In the next line T, enter an integer N in each line, which indicates there are n dice. (0 <n <= 1000) Note: 1. Each dice has six faces. 2. Each dice is the same. So (, 2) and (, 1) are the same results. The output outputs n dice at a time, which can throw several results. Because the result may be very large, the output result must be more than 1000007. Demo Input
212
Demo output
621
Prompt
Assume that only one dice is thrown, and the dice have six faces. Therefore, six possibilities can be thrown out.
If you throw two dice at a time, the possible results are as follows:
(1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6) 6
(2, 2) (2, 3) (2, 4) (2, 5) (2, 6) 5
(3, 3) (3, 4) (3, 5) (3, 6) 4
(4, 4) (4, 5) (4, 6) 3
(5, 5) (5, 6) 2
(6, 6) 1
That is, a total of 21 types total 21
A question during the school competition, at that time I still don't know what the recurrence is ..
Name the total number of dice starting with six types, that is, F [1] [J] -- F [6] [J] (j indicates the number of dice) f [7] [J] f [1] [J] -- F [6] [J] And the answer when the number of dice is J
The rule is that the dice starting with 1, that is, F [1] [J], whose value is equal to f [7] [J-1], and f [I] [J] = f [I-1] [J] -F [I-1] [J-1] (I> = 2) the rule is found on paper, and I cannot figure it out here .. It's not difficult to find the first four cases. It's almost the same.
# Include <iostream> // James's dice -- recurrence # include <algorithm> # include <cstdio> # include <cstring> using namespace STD; long long f [10] [1010]; const int mod = 1000007; int main () {int I, j, t, n; for (I = 1; I <= 6; I ++) f [I] [1] = 1; F [7] [1] = 6; For (j = 2; j <= 1010; j ++) {f [1] [J] = f [7] [J-1]; F [7] [J] = f [1] [J]; for (I = 2; I <= 6; I ++) {f [I] [J] = f [I-1] [J]-f [I-1] [J-1]; f [7] [J] + = f [I] [J] ;}} CIN >>> t; while (t --) {CIN >>> N; cout <F [7] [N] % mod <Endl;} return 0 ;}
James's dice (recurrence)