Nyoj 32 combination Number (deep search, nice, good question)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.