The combination of solving the sequence in DFS algorithm

Source: Internet
Author: User

/*

Pick 5 values from 13 books, what their combination might be,

The following code

DFS depth traversal, and full alignment is a method, but the thinking is different

*/

public class Main {
static int count = 0;
static int a[] = new INT[6];
public static void Main (string[] args) {
Boolean visit[] = new BOOLEAN[13];
DFS (a,visit,1);
System.out.println (count);
}

private static void Dfs (int[] A, boolean[] visit, int num) {
if (num==6) {
count++;
return;
}
for (a[num] = a[num-1]+1; A[num] < a[num]++) {//root permutation algorithm The difference is that this is not a[num]=1.
if (Visit[a[num]]==false) {
Visit[a[num]]=true;
num = num + 1;
DFS (A, visit, num);
num = num-1;
Visit[a[num]] = false;
}
}
}
}

The combination of solving the sequence in DFS algorithm

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.