Morse code(多模式串匹配)
链接:https://ac.nowcoder.com/acm/contest/3665/E
来源:牛客网
题目描述
Space is used to split Morse code, but if all spaces are lost, then the Morse code may have many meanings.For example: ".-. "can be translated to "AE"or "EN"or "R", but the string translated from Morse code can’t contain ’E’ and ’T’. So "R"is the longest string it can represent. Now hery is given a Morse code, he wants to know the length of the longest string it can represent.
输入描述:
The first line is an integer T, the number of test cases.
Next T lines, each line contains a Morse code consist of ’.’ and ’-’.
(1 ≤ T ≤ 100, the number of characters input will not exceed 10^6).
输出描述:
For each Morse code ,output the length of the longest string it can represent.
输入
..--.-.
--.-.--
输出
长度为2的4种情况已经全部出现过,长度为3的8种情况也已经出现过,因此我们一定能够利用长度为2或3的字母去填充,因此答案就是len/2。
此处给出dpdp做法,以供学习。
作者:Uncle_drew
链接:https://ac.nowcoder.com/discuss/363155?type=101
来源:牛客网 #include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
map<int,int>mp;
string code[];
char s[maxn];
int dp[maxn];
void init(){
code[]=".-"; code[]="-..."; code[]="-.-."; code[]="-..";
code[]="..-."; code[]="--."; code[]="....";
code[]=".."; code[]=".---"; code[]="-.-"; code[]=".-..";
code[]="--"; code[]="-."; code[]="---"; code[]=".--.";
code[]="--.-";code[]=".-."; code[]="...";
code[]="..-"; code[]="...-"; code[]=".--";code[]="-..-";
code[]="-.--"; code[]="--..";
for(int i=;i<=;i++){
int num=;
for(int j=;j<code[i].length();j++) num=num*+code[i][j];
mp[num]++;
}
}
int cal(int a,int b){
int num=;
for(int i=a;i<=b;i++) num=num*+s[i];
return mp[num]?:;
}
void solve(){
scanf("%s",s);
int n=strlen(s);
for(int i=;i<n;i++){
dp[i]=;
for(int j=;j<=;j++){
int y=i-j;
dp[i]=max(dp[i],dp[i-j]+cal(i-j+,i));
}
}
printf("%d\n",dp[n-]);
}
int main()
{
init();
int t;
scanf("%d",&t);
while(t--){
solve();
}
return ;
}
-
Morse code(多模式串匹配)的更多相关文章
- morse code
morse code,摩斯电码,是一种时通时断的信号代码,通过不同的排列顺序来表达不同的英文字母.数字和标点符号. 摩斯电码,是一种早期的数字化通信形式,但是它不同于现代只使用0和1两种状态的二进制代 ...
- Entity Framework 实体框架的形成之旅--Code First模式中使用 Fluent API 配置(6)
在前面的随笔<Entity Framework 实体框架的形成之旅--Code First的框架设计(5)>里介绍了基于Code First模式的实体框架的经验,这种方式自动处理出来的模式 ...
- 模式串匹配之KMP算法
模式串匹配之KMP算法 KMP算法 模式值计算(next[j]) (1) next[0]=-1, 第一个字符模式值为-1 (2) next[j]=-1, T中下标为j的字符与首字符相同,且j前面的1 ...
- 摩尔斯电码(Morse Code)Csharp实现
摩尔斯电码,在早期的"生产斗争"生活中,扮演了很重要的角色,作为一种信息编码标准,摩尔斯电码拥有其他编码方案无法超越的长久生命.摩尔斯电码在海事通讯中被作为国际标准一直使用到199 ...
- 模式串匹配KMP详解
关于KMP模式串匹配网上蛮多的. 对于KMP有自己理解所以写下来希望能够对你们的学习有帮助. 之前暑假的时候学过,然后好长时间没用发现又忘了,现在再看看发现有了新的理解. ============== ...
- AC自动机——多模式串匹配的算法思想
标准KMP算法用于单一模式串的匹配,即在母串中寻求一个模式串的匹配,但是现在又存在这样的一个问题,如果同时给出多个模式串,要求找到这一系列模式串在母串存在的匹配个数,我们应该如何处理呢? 基于KMP算 ...
- 基于EF Core的Code First模式的DotNetCore快速开发框架
前言 最近接了几个小单子,因为是小单子,项目规模都比较小,业务相对来说,也比较简单.所以在选择架构的时候,考虑到效率方面的因素,就采取了asp.net+entity framework中的code f ...
- 关于EF Code First模式不同建模方式对建表产生的影响
今天在学EF Code First模式的时候,发现几个很有趣的问题,问题如下: 1.当编写玩实体后,不指定任何主键约束,EF会找长的最像Id的,然后设置其为主键,验证代码如下: //User类 cla ...
- Leetcode 804. Unique Morse Code Words 莫尔斯电码重复问题
参考:https://blog.csdn.net/yuweiming70/article/details/79684433 题目描述: International Morse Code defines ...
随机推荐
- bzoj 4008、4011、1499
全是扒题解,,,太弱了... 不乱BB了. 4008 #include <bits/stdc++.h> #define LL long long #define lowbit(x) x&a ...
- JPA#复杂查询#引子
_ 震惊....简历上写精通JPA的被下面几个问题震呆了.... 几个问题: 复杂查询如何从前端传递到后端,特别是多个条件的.且具有and和or等复杂逻辑,这个要如何封装呢? 多表查询? 自定义sql ...
- 刷题23. Merge k Sorted Lists
一.题目说明 这个题目是23. Merge k Sorted Lists,归并k个有序列表生成一个列表.难度为Hard,实际上并不难,我一次提交就对了. 二.我的解答 就是k路归并,思路很简单,实现也 ...
- 133-PHP子类无法重写父类private同名函数
<?php class father{ //定义father类 //定义protected成员方法 protected function cook(){ return 'protected co ...
- centos7搭建kafka集群
一.安装jdk 1.下载jdk压缩包并移动到/usr/local目录 mv jdk-8u162-linux-x64.tar.gz /usr/local 2.解压 tar -zxvf jdk-8u162 ...
- 5分钟搞懂:session与cookie
http是无状态协议 无状态协议的意思是服务端与客户端不会记录任何一次通信的信息.诺兰有一部电影<记忆碎片>,说的是一个有"短期记忆丧失症"的人根据自己支离破碎的记忆来 ...
- 执行 composer update 命令的时候报 Your requirements could not be resolved to an installable set of packages. 错误
Your requirements could not be resolved to an installable set of packages. 以上原因:不匹配composer.json要求的版 ...
- 996.ICU 爆发,互联网从业者难逃“高薪陷阱”
从 3 月 27 日开始,截止本文发稿,GitHub 上面的项目 996.ICU 的 Star 数量已经超过 18 万,这场由程序员发动的轰轰烈烈的公开反对 996 工作制的运动,早已突破互联网圈层而 ...
- 14 ~ express ~ 显示用户数据
一,router/admin.js var express = require('express') var router = express.Router() var User = require( ...
- 三十一、CI框架之使用验证码
一.CI的验证码功能用着很是舒服,需要在根目录下新建一个captcha的验证码文件夹用于存放生产的图片,代码如下: 二.浏览器效果如下: 总结:关于验证码生产函数,有很多参数可以设置,包括字体,验证码 ...