Algorithm training 6-1 Recursive two-term coefficient value time limit: 10.0s memory Limit: 256.0MB problem Description Sample Enter an input example that satisfies the requirements of the topic.
3 10 Sample output corresponds to the output of the sample input above.
Data size and convention the range of each number in the input data.
Example: The result does not overflow when int is represented.
Topic Analysis:
for recursive problems, we pay attention to two points: (1) Find the exit; (2) Find similarity.
in the subject we know: (1) The export has been found: when k = 0 or k = n, the result is 1.
(2) similarity has also been found: when 0 < K < N, recursive call
Example code:
1 ImportJava.io.BufferedReader;2 Importjava.io.IOException;3 ImportJava.io.InputStreamReader;4 5 Public classMain {6 Public Static voidMain (string[] args)throwsioexception{7BufferedReader br =NewBufferedReader (NewInputStreamReader (system.in));8string[] str = Br.readline (). Split ("");9 intm = Integer.parseint (str[0]);Ten intn = integer.parseint (str[1]); One A intcoefficient =Binomialcoe (m,n); - - System.out.println (coefficient); the } - - Private Static intBinomialcoe (intKintN) { - if(k = = 0 | | k = =N) + return1; - returnBinomialcoe (k, n-1) + Binomialcoe (k-1, n-1); + } A}
Blue Bridge Cup algorithm training ALGO-150 6-1 recursive two-item coefficient value