Package first; import Java. util. stack; public class first {static int time = 10;/*** how many possibilities are there for a Shooting athlete to hit a target with a total of 10 rings and even a dozen shots and 90 rings? * Use recursionAlgorithmProgramming implementation. [H interview questions for a famous communication enterprise in China] * @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stub // Number of continuous shots // total number of rings for gun hitting int boomcount = 0; stack <integer> li = new stack <integer> (); hitprobability (Li, time, boomcount);} Private Static void hitprobability (stack <integer> Li, int time, int boomcount) {// todo auto-generated method stubif (Time> 0) {for (INT I = 0; I <11; I ++) {If (10 * (11-Time)-boomcount-I <= 10) {Li. push (I); hitprobability (Li, time-1, boomcount + I); Li. pop () ;}} else if (time = 0) {If (boomcount = 90) {for (int I: Li) {system. out. print (I + "--");} system. out. println ("");}}}}
============================================Program================ The following are the other two methods ====
===================================== First ==================== ================================ package digui; public class Daba {public int sum = 0;/***** @ Param time a total of times that can be tried. * @ Param score the number of rings required for time. * @ return time: the number of possible scores that are completed in the score. */Public int F (INT time, int score) {int all = 0; If (score/time> 10) return 0; If (time = 1) return 1; for (INT I = 0; I <= 10; I ++) {int TMP = f (1, I) * F (time-1, score-I ); if (TMP> = 1) All + = TMP ;} Return all;}/***** @ Param time total times * @ Param score the number of times required to reach the number of rings * @ Param ARR The number of rings in each time. */Public void F2 (INT time, int score, int [] ARR) {// system. out. println ("time =" + time + ", score =" + score); If (score/time> 10) return; If (time = 1) {arr [0] = score; output (ARR); Return ;}for (INT I = 0; I <= 10; I ++) {arr [time-1] = I; F2 (time-1, score-I, arr) ;}} private void output (INT [] ARR) {string result = ""; For (INT I = 0; I <= 9; I ++) {result + = arr [I] + "" ;}system. out. println (result); sum ++;} public Daba () {super (); // todo auto-generated constructor stub}/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stub Daba OBJ = new Daba (); // system. out. println (obj. F (10, 90); int [] arr = new int [10]; obj. f2 (10, 90, arr); system. out. println (obj. sum) ;}====== ========================= Second ============= =============== package digui; public class daba2 {// public static int [] store; // equivalent to setting the global variable sum. // The global variable sum is the public static int sum contained in the M class; public daba2 () {int sum = 0; // int [] store = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };} // print the function // print out the public static void output (INT [] store2) {string result = ""; for (INT I = 9; i> = 0; -- I) {// system. out. print (store2 [I] +" "); Result + = store2 [I] +" ";} system. out. println (result); sum ++;} // The total number of computations. The sum value is public static int sum2 () {return sum;} public static void cumput (INT score, int num, int [] store2) {// if the total score exceeds 90 loops (that is, score <0 ), or if the remaining score is greater than 10 rings and multiplied by the remaining number of hits, that is to say, even if the remaining score is 10 rings, the number of hits cannot be reached, exit recursion if (score <0 | score> (Num + 1) * 10) // The number of times num is 0 ~ 9 {return;} // if the condition is met and the last layer is reached if (num = 0) {store2 [num] = score; output (store2); return ;} for (INT I = 0; I <= 10; ++ I) {store2 [num] = I; cumput (score-I, num-1, store2 );} // console. write ("{0}", store2 [5]);} public static void main (string [] ARGs) {int [] store; store = new int [10]; int sum = 0; // int A = 90; // int B = 9; // output (); daba2.cumput (90, 9, store); sum = daba2.sum2 (); // M. cumput2 (a, B, store); // console. write ("{0}", store [3]); // cout <"Total number:" <sum <Endl; system. out. println (SUM );}}}