• 【例题 7-5 UVA


    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    每次枚举增加一个字符; 然后看看新生成的字符的后缀里面有没有出现连续子串就好,前面已经确认过的没必要重复确认 (枚举长度为偶数的一个后缀就好) 是输出完第64组且保证有第65组才要输出一个换行.

    【代码】

    import java.io.*;
    import java.util.*;
    public class Main{
        static int n,l,cnt;
        static int a[] = new int[1000];
        static ArrayList<Integer> list = new ArrayList<Integer>();
    
        static int dfs(int now){
            if (now > 1){
                cnt++;
                if (cnt==n){
                    for (int i = 1;i < now;i++) list.add(a[i]);
                    return 0;
                }
            }
            for (int i = 1;i <= l;i++){
                a[now] = i;
                boolean ok = true;
                for (int j = 1; now-2*j+1>=1;j++){
                    boolean ju = true;
                    for (int k = now-j+1;k<=now;k++){
                        if (a[k]!=a[k-j]){
                            ju = false;
                            break;
                        }
                    }
                    if (ju==true){
                        ok = false;
                        break;
                    }
                }
                if (!ok) continue;
                if (dfs(now+1)==0) return 0;
            }
            return 1;
        }
    
        public static void main(String args[]){
            Scanner cin = new Scanner(System.in);
            while (cin.hasNext()){
                n = cin.nextInt();l = cin.nextInt();
                if (n==0 && l==0) break;
                cnt = 0;
                list.clear();
                dfs(1);
                int tot = list.size();
                for (int i = 0;i < tot;i++){
                    if (i%4==0 && i >0) {
                        if (i % 64 == 0) {
                            System.out.println("");
                        } else {
                            System.out.print(' ');
                        }
                    }
                    System.out.print((char)(list.get(i)+'A'-1));
                }
                System.out.println("");
                System.out.println(tot);
            }
        }
    }
    
  • 相关阅读:
    Microsoft.Office.Inter.Excel.dll在調用時可能會出現如下錯誤
    Proe 导出PDF Vb.net
    给Eclipse安装Google app engine插件
    VC++ 2013 开发windows窗体程序
    GitHub使用说明
    c# 发送邮件
    c# aes 加密解密
    sourceforge软件下载方式
    keyCode转换成值
    前端写代码自动刷新神器Browsersync
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7986467.html
Copyright © 2020-2023  润新知