100723H Obfuscation
题目大意
给你一个包含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的更多相关文章
- [Android Tips] 14. Using Proguard with Android without obfuscation
Option -dontobfuscate REF Using Proguard with Android without obfuscation
- 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 ...
- .NET 中各种混淆(Obfuscation)的含义、原理、实际效果和不同级别的差异(使用 SmartAssembly)
长文预警!!! UWP 程序有 .NET Native 可以将程序集编译为本机代码,逆向的难度会大很多:而基于 .NET Framework 和 .NET Core 的程序却没有 .NET Nativ ...
- 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 ...
- HDU 2340 Obfuscation(dp)
题意:已知原串(长度为1~1000),它由多个单词组成,每个单词除了首尾字母,其余字母为乱序,且句子中无空格.给定n个互不相同的单词(1 <= n <= 10000),问是否能用这n个单词 ...
- Boosting Static Representation Robustness for Binary Clone Search against Code Obfuscation and Compiler Optimization(二)
接着上篇Asm2Vec神经网络模型流程继续,接下来探讨具体过程和细节. 一.为汇编函数建模 二.训练,评估 先来看第一部分为汇编函数建模,这个过程是将存储库中的每一个汇编函数建模为多个序列.由于 ...
- Boosting Static Representation Robustness for Binary Clone Search against Code Obfuscation and Compiler Optimization(一)
接着上一篇,现在明确问题:在汇编克隆搜索文献中,有四种类型的克隆[15][16][17]:Type1.literally identical(字面相同):Type2.syntactically equ ...
- Boosting Static Representation Robustness for Binary Clone Search against Code Obfuscation and Compiler Optimization
用于理解恶意软件的内部工作原理,并发现系统中的漏洞,逆向工程是一种耗费人工的却很重要的技术.汇编克隆搜索引擎是通过识别那些重复的或者已知的部件来帮助逆向工程师的工作,要想设计健壮的克隆搜索引擎是一项挑 ...
- HDU 2340 Obfuscation (暴力)
题意:给定一篇文章,将每个单词的首尾字母不变,中间顺序打乱,然后将单词之间的空格去掉,得到一个序列,给出一个这样的序列,给你一个字典,将原文翻译出来. 析:在比赛的时候读错题了,忘记首尾字母不变了,一 ...
随机推荐
- ICE的Glacier2使用
1.使用Glacier2的步骤: A.编写一个Glacier2的配置文件,参见样例 B.设置Glacier2的访问鉴权(密码或者证书),passwords文件每行样例"test xx ...
- UVA - 11768 Lattice Point or Not (扩展欧几里得)
求一条线段上有多少个整点. 是道扩欧基础题,列出两点式方程,然后分四种情况讨论即可.但细节处理较多很容易写挫(某zzWA了十几发才过掉的). 由于数据精度较小,浮点数比较没有用eps,直接==比较了. ...
- Web打印的处理 方案之普通报表打印
做过许多 的Web项目,大多数在打印页面内容的时刻 ,采用的都是议决 Javascript调用系统内置的打印要领 执行 打印,也就是调用 PrintControl.ExecWB(?,?)实现直接打印和 ...
- mysql之 Innobackupex全备恢复(原理、演示)
一. Innobackupex恢复原理 After creating a backup, the data is not ready to be restored. There might b ...
- Azure的CentOS上安装LIS (Linux Integration Service)
Azure上虚拟化技术都是采用的Hyper-v,每台Linux虚拟机都安装了LIS(Linux Integration Service).LIS的功能是为VM提供各种虚拟设备的驱动.所以LIS直接影响 ...
- 获得Oracke中刚插入的ID ---> GetInsertedID()
(1)首先 需要创建序列: CREATE SEQUENCE SE_TD_POWER MINVALUE 1 NOMAXVALUE START WITH 1 INCREMENT BY 1 NOCYCLE ...
- minidump-DMP文件的生成和使用
转载地址点击打开链接 1.生成dmp的程序 #include <dbghelp.h> #pragma comment(lib, "dbghelp.lib") //设 ...
- FFmpeg结构体:AVInputFormat
1.描述 AVInputFormat 是类似COM 接口的数据结构,表示输入文件容器格式,着重于功能函数,一种文件容器格式对应一个AVInputFormat 结构,在程序运行时有多个实例,位于avof ...
- 部署和调优 2.9 mysql主从配置-3
测试 先给主mysql解锁 > unlock tables; 删除一个表 > use db1; > show tables; > drop table help_categor ...
- Linux 压缩文件 和解压文件
.zip 解压:unzip FileName.zip 压缩:zip FileName.zip DirName .rar 解压:rar -x FileName.zip 压缩:rar -a FileNam ...