Question:NA dice is thrown to the ground, and the sum of all the dice toward the point aboveS. InputN, Print outSThe probability that all possible values.
To use dynamic planning, you still need to consider the idea ....
There is a simple method to solve this problem, that is, recursion.
Thought of the first dice one in 1-6, followed by n-1 sieve. Just calculate a sum.
# Include "stdio. H "int gmax = 6; void propcount (INT origin, int number, int sum, int * prop) {int I = 1; if (number = 1) {prop [Sum-origin] ++;} else {for (I = 1; I <= gmax; I ++) {propcount (origin, number-1, sum + I, Prop) ;}} void getprop (INT num) {int sum = 0; int I = 0; int * prop = (int *) malloc (sizeof (INT) * (Num * gmax-num + 1); memset (prop, 0, sizeof (INT) * (Num * gmax-num + 1 )); if (Num <= 0) return; for (I = 1; I <= gmax; I ++) propcount (Num, num, sum + I, Prop ); for (I = 0; I <num * gmax-num + 1; I ++) printf ("% d", prop [I]); free (PROP );} int main () {int num = 3; getprop (Num); Return 0 ;}
Through reading books, we found that the idea in the book is to establish a relationship by increasing the number of dice.
Two arrays need to be set
The first array n indicates the sum of the number of times the sieve is N.
The second array added a sieve n representing n-1, N-2, n-3, n-4, N-5, n-6, times.
The implementation of reading is very skillful. It took me some time to understand the principle.
# include "stdio. H "int gmax = 6; # define Max 1024 void getprop (INT num) {int prop [2] [Max]; int I = 0, j = 0; int flag = 0; int K; for (I = 0; I