Topic 1: Print all numbers from 1 to the maximum number of n digits. For example, N is 3, then print 1,2,3,4...999.
Title 2: Throw n dice on the ground, and the sum of the points on the top side of the dice is S. Enter N to print out the probability that all possible values of s will appear.
----------------
For topic 1, because the value of n can be large, direct print is not possible, and no data type can carry large n. For topic 2, the probability is to find the number of points and the frequency of the throw of S. These two topics have one thing in common, and they all have to do with a sequence, which can be described as: there are n boxes, each of which can be placed X1 to any number of Xn, outputting all possible emission patterns (possibly ordered). For topic 1, there are n boxes, each containing 0-9 of any number in the box, and a print sequence. For the title 2, it is N boxes, each box contains 1-6 of any number, counting the number of occurrences of the element in the box.
---------------
Pseudo-code for topic 1:
int* s=New int[n+1];//use S[n] to record the nth bit, S is the boxvoidPRINTN (intN//print 1 to maximum n-bit integers{ for(intI=0;i<Ten; i++) {S[n]=i; if(n>1) {PRINTN (n-1); } Else if(n==1) {print (S); //might need some processing, upside down, to knock off unwanted 0. } } }
For Topic 2, we don't need an array to represent the box, because we don't relate to what's in the box, we only care about the elements inside.
voidGetappeartimes (intNintEndintCursum,int*probility) { for(intI=1; i<=6; i++) { if(end==0) { //Probility[i] Storage and throw occurrences for Iprobility[cursum+i]++; } Else{getappeartimes (n,end-1, cursum+i,probility); } }}
[algorithm] fixed elements are fully arranged on fixed lengths