传送门

题目大意

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

分析

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

代码

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<string>
  5. #include<algorithm>
  6. #include<cctype>
  7. #include<cmath>
  8. #include<cstdlib>
  9. #include<queue>
  10. #include<ctime>
  11. #include<vector>
  12. #include<set>
  13. #include<map>
  14. #include<stack>
  15. using namespace std;
  16. #define sp cout<<"---------------------------------------------------"<<endl
  17. #define uli unsigned long long
  18. #define li long long
  19. char bs[],s[][];
  20. uli wsh[];
  21. int len[],dp[],nxt[];
  22. map<uli,int>mp[][];
  23. multiset<uli>HASH[][];
  24. int main(){
  25. srand(time()+);
  26. int n,m,i,j,t;
  27. for(i=;i<;i++)
  28. wsh[i]=(uli)rand()*rand()*rand()*rand()*rand()*rand()*rand()*rand();
  29. scanf("%d",&t);
  30. while(t--){
  31. for(i=;i<;i++)
  32. for(j=;j<;j++){
  33. HASH[i][j].clear();
  34. mp[i][j].clear();
  35. }
  36. scanf("%s",bs);
  37. scanf("%d",&n);
  38. m=strlen(bs);
  39. for(i=;i<=n;i++){
  40. scanf("%s",s[i]);
  41. len[i]=strlen(s[i]);
  42. uli hsh=;
  43. for(j=;j<len[i];j++)
  44. hsh+=wsh[s[i][j]-'a'];
  45. HASH[s[i][]-'a'][s[i][len[i]-]-'a'].insert(hsh);
  46. mp[s[i][]-'a'][s[i][len[i]-]-'a'][hsh]=i;
  47. }
  48. memset(dp,,sizeof(dp));
  49. memset(nxt,,sizeof(nxt));
  50. dp[m]=;
  51. for(i=m-;i>=;i--){
  52. uli hsh=;
  53. for(j=i;j<m;j++){
  54. hsh+=wsh[bs[j]-'a'];
  55. int x=HASH[bs[i]-'a'][bs[j]-'a'].count(hsh);
  56. if(x>&&dp[j+]){
  57. dp[i]+=x*dp[j+];
  58. nxt[i]=j+;
  59. }
  60. }
  61. dp[i]=min(dp[i],);
  62. }
  63. if(dp[]==)puts("impossible");
  64. else if(dp[]>)puts("ambiguous");
  65. else {
  66. for(i=;i<m;i=nxt[i]){
  67. uli hsh=;
  68. for(j=i;j<nxt[i];j++)
  69. hsh+=wsh[bs[j]-'a'];
  70. printf("%s ",s[mp[bs[i]-'a'][bs[nxt[i]-]-'a'][hsh]]);
  71. }
  72. puts("");
  73. }
  74. }
  75. return ;
  76. }

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. 2018.7.26 学会说NO,拒绝道德绑架。

    一.领导交给你一项不属于你工作范围的工作,是否需要拒绝,你可以考虑以下问题: 1.这是与我核心能力相关的工作吗?是,接受:否,进入下一条: 2.它能帮助我拓展我核心能力的边界,或是我感兴趣的吗?是,接 ...

  2. php实现word在线浏览功能。

    http://laoniangke.com/php/2012/10/08/php-doc-webview.html

  3. CodeForces - 794C:Naming Company(博弈&简单贪心)

    Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little thi ...

  4. 部署你的分布式调用链跟踪框架skywalking

    使用docker-compose 一键部署你的分布式调用链跟踪框架skywalking https://www.cnblogs.com/huangxincheng/p/9666930.html 一旦你 ...

  5. git-SSH连接配置

    1.1 在电脑端生成sshkey文件 打开git bash 输入: ssh-keygen -t rsa -C "xxxxxxx邮箱地址" 期间要输入两次密码[github远程添加s ...

  6. git之clone

    git clone 命令参数: usage: git clone [options] [--] <repo> [<dir>] -v, --verbose be more ver ...

  7. cpu高的问题的快速定位

    功能问题,通过日志,单步调试相对比较好定位. 性能问题,例如线上服务器CPU100%,如何找到相关服务,如何定位问题代码,更考验技术人的功底. 58到家架构部,运维部,58速运技术部联合进行了一次线上 ...

  8. .NET Framework、C#、CLR和Visual Studo之间的版本关系

    .NET Framework.C#.CLR和Visual Studo之间的版本关系 参考 .NET Framework.C#.CLR和Visual Studo之间的版本关系

  9. DataGridview刷新异常的问题

    datsSet 绑定到dataGrieView,在刷新dataSet的数据时,常会bug:索引0没有值或索引(int)x没有值 昨天弄了一个下午,发现bug原因: dataGridView中有数据时, ...

  10. java流类基础练习。

    总结:BufferedReader.InputStreamReader.字节与字符的区别. package com.ds; import java.io.*; //从控制台输入字符串,输到sdd时停止 ...