Full combination of Recursive Algorithms

Source: Internet
Author: User

Input:

Given the number of data N, then enter n numbers to find all the numbers.

Output:

Output the number of all arrays.

Sample input:

3

1 2 3

Sample output:

123

132

213

231

312

321

Ideas:

It is also a typical example of recursive solution.

The Code is as follows:

<Span style = "font-size: 14px;" >#include <stdio. h> # include <string. h> int A [110], B [110], C [110]; int N; void res (INT Len) {If (LEN> = N) // recursive end condition {for (INT I = 0; I <n; I ++) printf ("% d", C [I]); puts (""); return;} For (INT I = 0; I <n; I ++) {If (! B [I]) // use B [I] to determine whether a previous {B [I] = 1; C [Len] = A [I]; // copy the value to the array C [I] for output data res (LEN + 1); // perform a series of recursive B [I] = 0; // ensure that multiple groups of data can be output.} int main () {While (~ Scanf ("% d", & N) {for (INT I = 0; I <n; I ++) scanf ("% d ", & A [I]); // A [I] is used to temporarily store the element memset (B, 0, sizeof (B); // initialization, B [I] is used to mark res (0);} return 0 ;}</span>



Full combination of Recursive Algorithms

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.