• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

cynchanpin

  • 博客园
  • 联系
  • 订阅
  • 管理

View Post

HDU 4886 TIANKENG’s restaurant(Ⅱ) hash+dfs

题意:

1、找一个字符串s使得 s不是给定母串的子串

2、且s要最短

3、s在最短情况下字典序最小

hash。,,结果t掉了。。。加了个姿势怪异的hash值剪枝才过。。

#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
#define N 1000100
#define ll long long
#define mod 2496764 
char s[N];
short h[8][mod], tim;
bool f = false;
bool dfs(ll top, ll siz, ll dep) {
    if (siz > 1000000) return false;
    if(top == dep)
    {
        for(ll i = 0; i < 8; i++)
        {
            if(h[top][siz * 8 + i] != tim)
            {
                s[top] = i + 'A';
                s[top+1] = 0;
                f = true;
                return true;
            }
        }
        return false;
    }
    for(ll i = 0; i < 8; i++)
    {
        s[top] = i + 'A';
        if(dfs(top+1, siz * 8 + i, dep))return true;
    }
    return false;
}

int main(){
    int i, j, T; scanf("%d",&T);
    tim = 0;

    while(T--) {
        tim ++;
        scanf("%s", s);
        f = false;
        for(i = 0; s[i]; i++)
        {
            ll ans = 0;
            for(j = 0; j < 7 && s[i+j]; j++)
            {
                ans = ans * 8 + s[i + j] - 'A';
                h[j][ans] = tim;
            }
        }

       for(i = 0; i < 8; i++)
            if(dfs(0, 0, i))break;
        puts(s);
    }
    return 0;
}


posted on 2017-04-24 09:33  cynchanpin  阅读(169)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3