UVa 129 kryton Factor (dfs recursive search), kryptondfs

Source: Internet
Author: User

UVa 129 kryton Factor (dfs recursive search), kryptondfs


In the Backtracking Method, you only need to determine the suffix of the current string, instead of all the substrings.

# Include <iostream> # include <cstdio> using namespace std; int s [1000]; int n, l, cnt; int bfs (int cur) {if (cnt ++ = n) {for (int I = 0; I <cur; I ++) printf ("% c ", 'A '+ s [I]); cout <endl; return 0 ;}for (int I = 0; I <l; I ++) {s [cur] = I; int OK = 1; for (int j = 1; j * 2 <= cur + 1; j ++) {int equal = 1; for (int k = 0; k <j; k ++) if (s [cur-k]! = S [cur-k-j]) {equal = 0; break;} if (equal) {OK = 0; break ;}} if (OK) if (! Bfs (cur + 1) return 0;} return 1;} int main () {while (cin> n> l & n & l) {cnt = 0; bfs (0);} return 0 ;}


Related Article

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.