Combined number time limit: theMs | Memory Limit:65535KB Difficulty:3
-
-
Describe
-
Find all combinations of the number of R (0<r<=n) from the natural number 1, 2 、... 、 n (0<n<10).
-
-
Input
-
-
Enter N, R.
-
-
Output
-
-
Output all combinations in a specific order.
Specific order: The values in each combination are arranged from large to small, and the combinations are sorted in inverse dictionary order.
-
-
Sample input
-
-
5 3
-
-
Sample output
-
-
543542541532531521432431421321
-
-
Source
-
-
[Miao Building] Original
-
-
Uploaded by
Miao-dong Building
Unlike the way I did before, the previous was to directly lose all the possibilities, but now I need to output all the three-bit numbers, and output in descending order, and the new output three digits can not be the same as the previous three digits (the order of different also think I the same)! The TOP,V variable is cleverly used to assign values on the way to change. The method is very good!
The code is as follows:
#include <stdio.h>int n,r;int a[12];void dfs (int top,int v) {int i;if (v==0) {for (i=r;i>0;i--) {printf ("%d", A[i] );} Puts (""); return;} for (i=top;i>=v;--i) {A[v]=i;dfs (I-1,v-1);}} int main () {scanf ("%d%d", &n,&r);d FS (n,r); return 0;}
Nyoj 32 combination Number (deep search, nice, good question)