Number of Number of N-Take R

xiaoxiao2021-03-06  57

Recently, I am busy, I don't write something. When I was shopping in the afternoon, I found a small algorithm problem. I felt interesting, I spent a little time to write (time is squeezed out :) Netizen's question is as follows : I may not be clear, such as 1, 2, 3, 4, 5, 6, 7 these 7 numbers: their combination of any 6 numbers can only have the following cases: 1 2 3 4 5 61 3 4 5 6 71 2 4 5 6 71 2 3 5 6 71 2 3 4 6 71 2 3 4 5 72 3 4 5 6 7) ~ But the more combination of numbers, so I want to make a program Combine given it ~ This problem can be solved with recursive, nonsense, or look at the code, Public Class CodeForcomb {static int [] combdata = new int =NT [10];

Static void main () {a [0] = 6; // Print 6 Number of COMB (7, 6); // Take 6 different combinations in 7 7

}

Static Void Comb (INT M, INT K) {INT I, J; For (i = m; I> = K; I -) {Combdata [K] = i; if (k> 1) Comb (I-1 , K-1); // There are other combinations recursive

ELSE // has a set of combinations {for (j = a [0]; j> 0; j -) {console.write (combdata [j]);} console.writeLine ();} // else} / / for} // comb} // class

转载请注明原文地址:https://www.9cbs.com/read-111765.html

New Post(0)