• uva 129


    暴力求解

    大致题意 如果一个字符串含有相邻的重复字串称为容易的串,反之为非容易

    求字典序第n困难的串……

    大致思路,暴力如果是容易的串停过,然后困难的串继续求解tot++

    总之先记着吧……

    最后输出格式……

    uva 129

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <cstdlib>
    #include <stack>
    #include <cctype>
    #include <string>
    #include <malloc.h>
    #include <queue>
    #include <map>
    
    using namespace std;
    const int INF = 0xffffff;
    const double esp = 10e-8;
    const double Pi = 4 * atan(1.0);
    const int Maxn = 200 + 10;
    const int mod = 10000007;
    const int dr[] = {1,0,-1,0,-1,1,-1,1};
    const int dc[] = {0,1,0,-1,1,-1,-1,1};
    //int dir2[8][2] = {{-1,0},{0,-1},{-1,1},{1,-1},{-1,-1},{1,0},{0,1},{1,1}};
    
    int n,L;
    int a[1000];
    int tot;
    
    bool dfs(int cur){
      if(tot++ == n){
        for(int i = 0;i < cur;i++){
            if(i && i % 4 == 0){
                if(i % (16*4) == 0){
                    cout << endl;
                    //cout << "$$$$";
                }
                else
                    cout << ' ';
            }
            cout << char(a[i] + 'A');
        }
        cout << endl;
        cout << cur << endl;
        return 0;
      }
      for(int i = 0;i < L;i++){
        a[cur] = i;
        bool ok = 1;
        for(int j = 1;j * 2 < cur+2;j++){
            bool flag = 1;
            for(int k = 0;k < j;k++){
                if(a[cur-k] != a[cur-k-j]){
                    flag = 0;
                    break;
                }
            }
            if(flag){
                ok = 0;
                break;
            }
        }
        if(ok){
            if(!dfs(cur+1)){
                return 0;
            }
        }
      }
      return 1;
    }
    
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("inpt.txt","r",stdin);
    #endif
        while(cin >> n >> L){
            if(!n && !L)
                break;
            tot = 0;
            dfs(0);
        }
        return 0;
    }
    View Code

    回家一直在玩,好难过……!!!!

    以后要加油……!!!

  • 相关阅读:
    使用docker部署微服务
    配置git仓库SSH秘钥,实现免密登录
    windows添加打印机失败
    流媒体之HLS与DASH
    docker安装mysql8.0
    去它的不要找客观原因
    idea提交代码到gitee报错:The requested URL returned error: 403
    使用docker compose微服务编排
    docker安装redis
    OpenGL环境安装
  • 原文地址:https://www.cnblogs.com/hanbinggan/p/4284296.html
Copyright © 2020-2023  润新知