传送门

题目大意

给你一个包含n 个单词的字典,给你一篇文章,文章包括若干词典里的单词,把句子里的空格都去掉,单词的首位字母都不变,中间的字符集为乱序,问能否恢复这篇文章,使得单词都是词典里的单词,如果有唯一解,输出唯一解。

分析

可以将将一段字符串哈希来确定这段字符串的字母组成,在记录每一段的首字母和尾字母,这样便可以将整段字符表示出来了,在进行完预处理之后我们进行dp,用dpi表示i+1到m这一段的字符可以由先有字母表组成几个。最后如果dp0有0个则代表无法组成,大于1则有歧义,等于一则根据之前记录的nxt数组和每一段字符对应的编号将答案输出。详见代码。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define sp cout<<"---------------------------------------------------"<<endl
#define uli unsigned long long
#define li long long
char bs[],s[][];
uli wsh[];
int len[],dp[],nxt[];
map<uli,int>mp[][];
multiset<uli>HASH[][];
int main(){
srand(time()+);
int n,m,i,j,t;
for(i=;i<;i++)
wsh[i]=(uli)rand()*rand()*rand()*rand()*rand()*rand()*rand()*rand();
scanf("%d",&t);
while(t--){
for(i=;i<;i++)
for(j=;j<;j++){
HASH[i][j].clear();
mp[i][j].clear();
}
scanf("%s",bs);
scanf("%d",&n);
m=strlen(bs);
for(i=;i<=n;i++){
scanf("%s",s[i]);
len[i]=strlen(s[i]);
uli hsh=;
for(j=;j<len[i];j++)
hsh+=wsh[s[i][j]-'a'];
HASH[s[i][]-'a'][s[i][len[i]-]-'a'].insert(hsh);
mp[s[i][]-'a'][s[i][len[i]-]-'a'][hsh]=i;
}
memset(dp,,sizeof(dp));
memset(nxt,,sizeof(nxt));
dp[m]=;
for(i=m-;i>=;i--){
uli hsh=;
for(j=i;j<m;j++){
hsh+=wsh[bs[j]-'a'];
int x=HASH[bs[i]-'a'][bs[j]-'a'].count(hsh);
if(x>&&dp[j+]){
dp[i]+=x*dp[j+];
nxt[i]=j+;
}
}
dp[i]=min(dp[i],);
}
if(dp[]==)puts("impossible");
else if(dp[]>)puts("ambiguous");
else {
for(i=;i<m;i=nxt[i]){
uli hsh=;
for(j=i;j<nxt[i];j++)
hsh+=wsh[bs[j]-'a'];
printf("%s ",s[mp[bs[i]-'a'][bs[nxt[i]-]-'a'][hsh]]);
}
puts("");
}
}
return ;
}

100723H Obfuscation的更多相关文章

  1. [Android Tips] 14. Using Proguard with Android without obfuscation

    Option -dontobfuscate REF Using Proguard with Android without obfuscation

  2. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B. Code obfuscation 水题

    B. Code obfuscation 题目连接: http://codeforces.com/contest/765/problem/B Description Kostya likes Codef ...

  3. .NET 中各种混淆(Obfuscation)的含义、原理、实际效果和不同级别的差异(使用 SmartAssembly)

    长文预警!!! UWP 程序有 .NET Native 可以将程序集编译为本机代码,逆向的难度会大很多:而基于 .NET Framework 和 .NET Core 的程序却没有 .NET Nativ ...

  4. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B - Code obfuscation

    地址:http://codeforces.com/contest/765/problem/B 题目: B. Code obfuscation time limit per test 2 seconds ...

  5. HDU 2340 Obfuscation(dp)

    题意:已知原串(长度为1~1000),它由多个单词组成,每个单词除了首尾字母,其余字母为乱序,且句子中无空格.给定n个互不相同的单词(1 <= n <= 10000),问是否能用这n个单词 ...

  6. Boosting Static Representation Robustness for Binary Clone Search against Code Obfuscation and Compiler Optimization(二)

    接着上篇Asm2Vec神经网络模型流程继续,接下来探讨具体过程和细节. 一.为汇编函数建模  二.训练,评估   先来看第一部分为汇编函数建模,这个过程是将存储库中的每一个汇编函数建模为多个序列.由于 ...

  7. Boosting Static Representation Robustness for Binary Clone Search against Code Obfuscation and Compiler Optimization(一)

    接着上一篇,现在明确问题:在汇编克隆搜索文献中,有四种类型的克隆[15][16][17]:Type1.literally identical(字面相同):Type2.syntactically equ ...

  8. Boosting Static Representation Robustness for Binary Clone Search against Code Obfuscation and Compiler Optimization

    用于理解恶意软件的内部工作原理,并发现系统中的漏洞,逆向工程是一种耗费人工的却很重要的技术.汇编克隆搜索引擎是通过识别那些重复的或者已知的部件来帮助逆向工程师的工作,要想设计健壮的克隆搜索引擎是一项挑 ...

  9. HDU 2340 Obfuscation (暴力)

    题意:给定一篇文章,将每个单词的首尾字母不变,中间顺序打乱,然后将单词之间的空格去掉,得到一个序列,给出一个这样的序列,给你一个字典,将原文翻译出来. 析:在比赛的时候读错题了,忘记首尾字母不变了,一 ...

随机推荐

  1. LeetCode OJ:Contains DuplicateII(是否包含重复II)

    Given an array of integers and an integer k, find out whether there are two distinct indices i and j ...

  2. 条款47:请使用traits class表示类型信息

    在stl的算法中,我们的希望往往是根据不同的迭代器类型进行不同的更有效率的操作: template<typename IterT, typename DistT> void advance ...

  3. linux使用收集

    Centos7 命令 # 查询正运行的java进程,建议使用jps,使用ps会将tail也显示出来 jps -lvm | grep '/home/chencye/tomcat/apache-tomca ...

  4. Operating System-进程间互斥的方案-保证同一时间只有一个进程进入临界区(3)- TSL指令

    本文接上一篇文章继续介绍如何实现同一时间只允许一个进程进入临界区的机制.本文主要介绍TSL指令. 方案汇总 屏蔽中断 锁变量 严格轮换法 TSL指令 Peterson解法 一.What is TSL ...

  5. 3、Selenium调用IEDriverServer打开IE浏览器

    学习Selenium时若想调用IE浏览器,均需要以下步骤 (1).http://selenium-release.storage.googleapis.com/index.html 下载IEDrive ...

  6. 基于TCP协议 I/O多路转接(select) 的高性能回显服务器客户端模型

    服务端代码: myselect.c #include <stdio.h> #include <netinet/in.h> #include <arpa/inet.h> ...

  7. SpringCloud组件的简单介绍

    springcloud官网springcloud中文网站 最近开始接触springcloud,所以先了解了一下最最基本概念. Spring Cloud ConfigSpring配置管理工具包,让你可以 ...

  8. 四川第七届 C Censor (字符串哈希)

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...

  9. Rails上传文件

    1.view <%= form_tag({:method =>"post",:controller =>"welcome",:action=& ...

  10. springmvc----demo3---rest风格---bai

    input_stu_path.jsp: showinput_stu_path.jsp: