链接:https://ac.nowcoder.com/acm/contest/3665/E
来源:牛客网

题目描述

Morse code is a character encoding scheme used in telecommunication that encodes text characters as standardized sequences of two different signal durations called dots and dashes or dits and dahs. Morse code is named for Samuel F. B. Morse, an inventor of the telegraph.

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.

示例1

输入

..--.-.
--.-.--

输出


长度为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 ;
}

-

最新文章

  1. Android Service
  2. 如何选择 compileSdkVersion, minSdkVersion 和 targetSdkVersion
  3. Android RelativeLayout用到的一些重要的属性
  4. 【splay模板】
  5. 【BZOJ】3673: 可持久化并查集 by zky &amp; 3674: 可持久化并查集加强版(可持久化线段树)
  6. Android之Button自定义点击效果
  7. hadoop2.20.0集群安装教程
  8. SGU 167.I-country
  9. C# 导出 excel 复杂格式 html导出
  10. DDFT
  11. Java中修饰符
  12. Canvas 宽度、高度设置
  13. String、StringBuilder和StringBuffer类
  14. chrome调试工具高级不完整使用指南(实战二)
  15. 有没有最好的学习Angularjs2的视频入门体验?
  16. 新装云服务器没有iptables 文件,并且无法通过service iptables save操作
  17. (二)文档请求不同源之flash跨域
  18. TypeScript安装备忘:npm proxy设置
  19. C#的delegate简单练习
  20. linux log

热门文章

  1. [YOLO]《YOLO9000:Better, Faster, Stronger》笔记
  2. Python基础笔记:list和tuple
  3. 七十九、SAP中数据库操作之更新数据,UPDATE的用法
  4. 七十七、SAP中数据库操作之多表联合查询
  5. HDU 2586 LCA-Tarjan
  6. 干货分享:深度解析Supplement Essay写作
  7. Git提交出现error: src refspec master does not match any的问题
  8. flutter文本简单实现
  9. POJ 1039:Pipe 计算几何
  10. hibernate.QueryException: Legacy-style query parameters (`?`) are no longer supported