5. Draw lots (code blanks)
Planet X is sending a 5-man observer mission to the W-Star.
which
A country can send up to 4 people.
A maximum of 2 people can be dispatched in country B.
C countries can send up to 2 people.
....
So how many different combinations of the country will eventually be sent to the W-Star's Observer mission?
The following procedure resolves this problem.
Array a[] is the largest number of places each country can send.
The results of the program execution are:
Defff
Cefff
Cdfff
Cdeff
Ccfff
Cceff
Ccdff
Ccdef
Befff
Bdfff
Bdeff
Bcfff
Bceff
Bcdff
Bcdef
....
(omitted below, total 101 lines)
1 Public class_5 Lottery {2 Public Static voidMain (string[] args) {3 int[] A = {4,2,2,1,1,3}; 4F (a,0,5, ""); 5 }6 Public Static voidFint[] A,intKintN, String s)7 { 8 if(k==a.length) { 9 if(n==0) System.out.println (s); Ten return; One } AString s2 =s; - for(inti=0; i<=a[k]; i++){ - //This should be filled with f (A, k+1, 5-s2.length (), S2) theF (A, k+1, 5-s2.length (), S2);//fill in the blanks -S2 + = (Char) (k + ' A '); - } - } +}
Java Algorithm Blue Bridge Cup (question + answer) lottery