1432 Decoding Morse Sequences

原创 2007年10月15日 08:22:00
Decoding Morse Sequences
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 418   Accepted: 177

Description
Before the digital age, the most common "binary" code for radio communication was the Morse code. In Morse code, symbols are encoded as sequences of short and long pulses (called dots and dashes respectively). The following table reproduces the Morse code for the alphabet, where dots and dashes are represented as ASCII characters "." and "-":

 

Input
The first line of the input contains exactly one positive integer d equal to the number of data sets, 1 <= d <= 20. The data sets follow.

The first line of each data set contains a Morse sequence - a nonempty sequence of at most 10 000 characters "." and "-" with no spaces in between.

The second line contains exactly one integer n, 1 <= n <= 10 000, equal to the number of words in a dictionary. Each of the following n lines contains one dictionary word - a nonempty sequence of at most 20 capital letters from "A" to "Z". No word occurs in the dictionary more than once.

Output
The output should consist of exactly d lines, one line for each data set. Line i should contain one integer equal to the number of distinct phrases into which the Morse sequence from the i-th data set can be parsed. You may assume that this number is at most 2 * 10^9 for every single data set.

Sample Input

 

Sample Output

 

Source
Central Europe 2001

 **********************************************************************************

*************************************************************************************

Source Code
#include<stdio.h>
#include<string.h>
char Morse[26][5]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
int best[10001],n,len;
char s[10001],dic[10001][30],word[10001][101];
void init()
{
int i,j;
memset(word,'/0',sizeof(word));
for(i=0;i<n;i++)
   for(j=0;j<strlen(dic[i]);j++)
    strcat(word[i],Morse[dic[i][j]-'A']);
memset(best,0,sizeof(best));
best[0]=1;
//for(i=0;i<n;i++)
//    printf("%s/n",word[i]);
}
void DP()
{
int i,j,k,flag;
for(i=0;i<=len;i++)
   if(best[i])
    for(j=0;j<n;j++)
    {
     flag=1;
     for(k=0;k<strlen(word[j]);k++)
     {
      if(i+k==len)break;
      if(s[i+k]!=word[j][k]){flag=0;break;}
     }
     if(flag)best[i+strlen(word[j])]+=best[i];
    }
printf("%d/n",best[len]);
}
int main()
{
int cas,i;
scanf("%d",&cas);
while(cas--)
{
   scanf("%s%d",s,&n);
   len=strlen(s);
   for(i=0;i<n;i++)
    scanf("%s",dic[i]);
   init();
   DP();
}
}

2
1
.---.--.-.-.-.---...-.---.
6
AT
TACK
TICK
ATTACK
DAWN
DUSK

Notice that in the absence of pauses between letters there might be multiple interpretations of a Morse sequence. For example, the sequence -.-..-- could be decoded both as CAT or NXT (among others). A human Morse operator would use other context information (such as a language dictionary) to decide the appropriate decoding. But even provided with such dictionary one can obtain multiple phrases from a single Morse sequence.


Task

Write a program which for each data set:

reads a Morse sequence and a list of words (a dictionary),

computes the number of distinct phrases that can be obtained from the given Morse sequence using words from the dictionary,

writes the result.

Notice that we are interested in full matches, i.e. the complete Morse sequence must be matched to words in the dictionary.

总结 | 近期Chatbot领域值得读的paper

引言 Chatbot大热不仅仅是工业界的现象,学术界也跟着烧起了一把火。本文汇总了最近半年内质量比较高的paper,旨在给想了解这一领域的学生、老师和算法工程师们一个reading list,...
  • AMDS123
  • AMDS123
  • 2017年01月20日 17:49
  • 7379

FFmpeg的H.264解码器源代码简单分析:熵解码(Entropy Decoding)部分

本文分析FFmpeg的H.264解码器的熵解码(Entropy Decoding)部分的源代码。FFmpeg的H.264解码器调用decode_slice()函数完成了解码工作。这些解码工作可以大体上...
  • leixiaohua1020
  • leixiaohua1020
  • 2015年04月18日 17:19
  • 10262

Windows环境下使用VS2010编译OpenSSL

准备工作: 1、安装VC++ 2010。 2、需要perl的支持,下载最新ActivePerl并安装,网址:http://www.activestate.com/ 3、下载 Openssl并解压...
  • swanabin
  • swanabin
  • 2015年09月12日 17:23
  • 1921

POJ 1432 Decoding Morse Sequences

题意给出一个字母的译码表,给出一个有n个单词的字典,给出一串编码。问再给出字典中有多少种不同的解码方式。分析首先编码只有-和.,可以很方便地建立一棵Trie树,还是最熟悉的二叉方式。 然...
  • D042412
  • D042412
  • 2015年07月16日 19:21
  • 418

baiduinput_ipad_v2.0.0.19_1432c

  • 2015年06月09日 09:06
  • 2.93MB
  • 下载

Morse theory

  • 2010年10月20日 13:19
  • 5.43MB
  • 下载

morse电报发送器

  • 2014年03月24日 23:32
  • 2KB
  • 下载

摩尔斯电码(morse)转换英文字符串c语言代码

找到这篇文章说明你对摩尔斯电码很赶兴趣,而且你已掌握了莫尔斯电码的基础知识了。想更贴近的感受一下莫尔斯电码的魅力。或你有一个非常棒的关于莫尔斯电码想法而非常激动。如果是这样的话,那你或许会从我的代码中...
  • robert_cysy
  • robert_cysy
  • 2015年12月20日 19:41
  • 1892

Morse Code HNUST 1675(字符串全排列 递归解决 数组a[]与流输入的缓慢)

题目描述  摩尔斯电码(英语:Morse Code)是一种时通时断的信号代码,通过不同的排列顺序来表达不同的英文字母、数字和标点符号。是由美国人萨缪尔·摩尔斯在1836年发明。            ...
  • deepseazbw
  • deepseazbw
  • 2017年12月09日 16:48
  • 23

[MI-BCI论文札记]基于Morse电码的多类运动想象BCI系统设

本文主要的贡献是将传统MI-BCI仅有二类运动想象识别(左手、右手)增加到了六类,用来控制六种运动想象的结果,但是实际上人的想象只有传统的三种,文中的办法是采用莫斯电码,用运动想象序列进行编码,可以得...
  • dzbs2015
  • dzbs2015
  • 2015年12月06日 11:01
  • 289
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:1432 Decoding Morse Sequences
举报原因:
原因补充:

(最多只允许输入30个字)