HDU 1523 Decoding Morse Sequences
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1523
此题大意为 给你一串摩尔斯密码 再给你一个字典(下面单词本)
用下面的单词组合成给你的摩尔斯密码, 问最多有多少种不同的组合方式。
题解分析:
1.设字符串的长度为len , 判断dp[i]处是否可达, 若可达则遍历整个单词表。
2.要先把dp[0]设为1,遍历单词表,若此单词可以在 i 处匹配则 dp[i+L] += dp[i], L(这个单词转成摩尔斯密码后的字符长度);
3.最后输出dp[len];
下面是代码:
#include<stdio.h>
#include<string.h> char Morse[][]={{".-"},{"-..."},{"-.-."},{"-.."},
{"."},{"..-."},{"--."},{"...."},{".."},{".---"},{"-.-"},{".-.."},
{"--"},{"-."},{"---"},{".--."},{"--.-"},{".-."},{"..."},{"-"},
{"..-"},{"...-"},{".--"},{"-..-"},{"-.--"},{"--.."}}; char Dict[][];//字典保存每个单词
int dp[];
int main()
{
int T, i, n, len, j, a;
char str[], str2[];
scanf("%d",&T);
while(T--)
{
scanf("%s",str);
len = strlen(str);
scanf("%d",&n);
memset(dp,,sizeof(dp));
for(i=; i<n; i++)//转化词典
{
Dict[i][]=NULL;//每次到要初始化 scanf("%s",str2);
for(j=; str2[j]; j++)
strcat(Dict[i],Morse[str2[j]-'A']);
}
dp[] = ;
for(i=; i<len; i++)
{
if(dp[i])
{
for(j=; j<n; j++)
{
a = strlen(Dict[j]); if(strncmp(str+i,Dict[j],a) == )//若此处可以匹配
dp[i+a] += dp[i];
}
}
}
printf("%d\n",dp[len]);
}
return ;
}
HDU 1523 Decoding Morse Sequences的更多相关文章
- POJ 1432 Decoding Morse Sequences (DP)
Decoding Morse Sequences 题目链接: http://acm.hust.edu.cn/vjudge/contest/129783#problem/D Description Be ...
- poj-Decoding Morse Sequences(动态规划)
Description Before the digital age, the most common "binary" code for radio communication ...
- 别人整理的DP大全(转)
动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...
- [转] POJ DP问题
列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 13 ...
- poj动态规划列表
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...
- POJ动态规划题目列表
列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 13 ...
- 狗狗40题~ (Volume C)
A - Triangles 记忆化搜索呗.搜索以某三角形为顶的最大面积,注意边界情况. #include <stdio.h> #include <cstring> #inclu ...
- POJ 动态规划题目列表
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
随机推荐
- css考核点整理(十一)-响应式开发经验,响应式页面的三种核心技术是什么
响应式开发经验,响应式页面的三种核心技术是什么
- DIV布局之道三:DIV块的覆盖,DIV层遮盖其他DIV
DIV布局网页的第三种方式:覆盖.DIV覆盖方式经常应用于网页弹出框的制作,例如在网店系统中,当用户没有登录时,点击购买,系统弹出一个登陆框. 请看代码: HTML部分: XML/HTML Code复 ...
- HTML5 History对象,Javascript修改地址栏而不刷新页面(二)
一.实例说明: $('#btnOne').click(function () { var stateObject = { id: 1 }; var title = "本地首页"; ...
- updatepanel局部刷新功能,实现注册时对用户名的检测
updatepanel的使用 通过将控件放入到updatepanel中,实现局部刷新. 前台代码:<asp:ScriptManager ID="ScriptManager1" ...
- angularjs google map markers+ ui-gmap-windows --->增加click 事件
jsp: <div class="modal-body viewOnMap"> <div class="cboxClose" ng-click ...
- padding and margin.
padding is the space between the content and the border, whereas margin is the space outside the bor ...
- Oracle利用dbms_metadata.get_ddl查看DDL语句
当我们想要查看某个表或者是表空间的DDL的时候,可以利用dbms_metadata.get_ddl这个包来查看. dbms_metadata包中的get_ddl函数详细参数 GET_DDL函数返回创建 ...
- 介绍一个小工具 Linqer
http://www.cnblogs.com/huangxincheng/archive/2011/05/12/2044990.html
- xml中报错,验证是否是xml报错
1.xml中写入sql有时报错,例如有大于号小于号,要用<![CDATA[ ]]>扩起来 2.验证xml有错的方式,以浏览器方式打开,如果正常打开,无错. ...
- 欢迎使用 Markdown 编辑器写博客
本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦: Markdown和扩展Markdown简洁的语法 代码块高亮 图片链接和图片上传 LaTex数学公式 UML ...