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 (暴力)
题意:给定一篇文章,将每个单词的首尾字母不变,中间顺序打乱,然后将单词之间的空格去掉,得到一个序列,给出一个这样的序列,给你一个字典,将原文翻译出来. 析:在比赛的时候读错题了,忘记首尾字母不变了,一 ...
随机推荐
- 2018.7.26 学会说NO,拒绝道德绑架。
一.领导交给你一项不属于你工作范围的工作,是否需要拒绝,你可以考虑以下问题: 1.这是与我核心能力相关的工作吗?是,接受:否,进入下一条: 2.它能帮助我拓展我核心能力的边界,或是我感兴趣的吗?是,接 ...
- php实现word在线浏览功能。
http://laoniangke.com/php/2012/10/08/php-doc-webview.html
- CodeForces - 794C:Naming Company(博弈&简单贪心)
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little thi ...
- 部署你的分布式调用链跟踪框架skywalking
使用docker-compose 一键部署你的分布式调用链跟踪框架skywalking https://www.cnblogs.com/huangxincheng/p/9666930.html 一旦你 ...
- git-SSH连接配置
1.1 在电脑端生成sshkey文件 打开git bash 输入: ssh-keygen -t rsa -C "xxxxxxx邮箱地址" 期间要输入两次密码[github远程添加s ...
- git之clone
git clone 命令参数: usage: git clone [options] [--] <repo> [<dir>] -v, --verbose be more ver ...
- cpu高的问题的快速定位
功能问题,通过日志,单步调试相对比较好定位. 性能问题,例如线上服务器CPU100%,如何找到相关服务,如何定位问题代码,更考验技术人的功底. 58到家架构部,运维部,58速运技术部联合进行了一次线上 ...
- .NET Framework、C#、CLR和Visual Studo之间的版本关系
.NET Framework.C#.CLR和Visual Studo之间的版本关系 参考 .NET Framework.C#.CLR和Visual Studo之间的版本关系
- DataGridview刷新异常的问题
datsSet 绑定到dataGrieView,在刷新dataSet的数据时,常会bug:索引0没有值或索引(int)x没有值 昨天弄了一个下午,发现bug原因: dataGridView中有数据时, ...
- java流类基础练习。
总结:BufferedReader.InputStreamReader.字节与字符的区别. package com.ds; import java.io.*; //从控制台输入字符串,输到sdd时停止 ...