1001. Alphacode

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Alice and Bob need to send secret messages to each other and are discussing ways to encode their messages: Alice: "Let's just use a very simple code: We'll assign `A' the code word 1, `B' will be 2, and so on down to `Z' being assigned 26." Bob: "That's a stupid code, Alice. Suppose I send you the word `BEAN' encoded as 25114. You could decode that in many different ways!" Alice: "Sure you could, but what words would you get? Other than `BEAN', you'd get `BEAAD', `YAAD', `YAN', `YKD' and `BEKD'. I think you would be able to figure out the correct decoding. And why would you send me the word `BEAN' anyway?" Bob: "OK, maybe that's a bad example, but I bet you that if you got a string of length 500 there would be tons of different decodings and with that many you would find at least two different ones that would make sense." Alice: "How many different decodings?" Bob: "Jillions!" For some reason, Alice is still unconvinced by Bob's argument, so she requires a program that will determine how many decodings there can be for a given string using her code.

Input

Input will consist of multiple input sets. Each set will consist of a single line of digits representing a valid encryption (for example, no line will begin with a 0). There will be no spaces between the digits. An input line of `0' will terminate the input and should not be processed

Output

For each input set, output the number of possible decodings for the input string. All answers will be within the range of a long variable.

Sample Input

25114
1111111111
3333333333
0

Sample Output

6
89
1 比较简单的动态规划,值得注意的是qq[i] == '0'的情况(我一开始也没有注意到,WA了几遍,给跪了)。
//很简单的动态规划
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string ss;
while(cin >> ss && ss != "0")
{
vector<long> qq;
int len = ss.length();
qq.resize(len+1);
int i;
qq[0] = 1;
qq[1] = 1;
for(i = 1;i < ss.size();i++)
{
if(ss[i] == '0')
qq[i+1] = qq[i-1];
else if((ss[i] >= '1' && ss[i] <= '9' && ss[i-1] == '1')||(ss[i] >= '1' && ss[i] <= '6' && ss[i-1] == '2'))
qq[i+1] = qq[i] + qq[i-1];
else
qq[i+1] = qq[i];
}
cout << qq[len] << endl;
}
return 0;
}
												

soj1001. Alphacode的更多相关文章

  1. SPOJ-394-ACODE - Alphacode / dp

    ACODE - Alphacode #dynamic-programming Alice and Bob need to send secret messages to each other and ...

  2. POJ 2033 Alphacode

    Alphacode Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11666   Accepted: 3564 Descri ...

  3. poj 2033 Alphacode (dp)

    Alphacode Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13378   Accepted: 4026 Descri ...

  4. soj1001算法分析

    题目简单描述: 给定一个长数串,输出可能的字母串解个数.(A对应1,Z对应26) 样例输入:25114 样例输出:6 样例解释:可能的字母串解:YJD.YAAD.YAN.BEJD.BEAAD.BEAN ...

  5. 【HDOJ】1508 Alphacode

    简单DP.考虑10.20(出现0只能唯一组合).01(不成立). /* 1508 */ #include <iostream> #include <string> #inclu ...

  6. 别人整理的DP大全(转)

    动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...

  7. dp题目列表

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  8. poj 动态规划题目列表及总结

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  9. [转] POJ DP问题

    列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 13 ...

随机推荐

  1. node websocket学习研究

    websocket作为不同于http的数据传输方式,是开发一些实时系统的不二选择. 最近在研究开发websocket方面的小程序.小程序客户端直接对websocket做了封装.自己只要写后端就可以了. ...

  2. redis批量删除key 命令

    redis-cli -n 数据库编号 -a 密码 keys "过滤条件" | xargs redis-cli -n 数据库编号 -a 密码 del Demo: redis-cli ...

  3. scrapy学习笔记(三):使用item与pipeline保存数据

    scrapy下使用item才是正经方法.在item中定义需要保存的内容,然后在pipeline处理item,爬虫流程就成了这样: 抓取 --> 按item规则收集需要数据 -->使用pip ...

  4. 【vue】import的使用

    以下是vue默认模板结构,自动加载HelloWorld (1)@ 等价于 /src 这个目录,避免写麻烦又易错的相对路径,是在webpack.base.config.js里面配置好别名 (2)impo ...

  5. IE实现userData 永久存储

      注意:只支持IE5,及其以上的浏览器 //需要使用 if 条件注释 <!DOCTYPE html> <html> <head> <meta charset ...

  6. 多进程编程之system()函数

    1.system函数: 使用函数system,在程序中执行一个shell命令字符串很方便.它是一个和操作系统紧密相关的函数,用户可以使用它在自己的程序中调用系统提供的各种命令,执行系统的命令行,其实也 ...

  7. C 数据类型——Day02

    C 数据类型 在 C 语言中,数据类型指的是用于声明不同类型的变量或函数的一个广泛的系统.变量的类型决定了变量存储占用的空间,以及如何解释存储的位模式. C 中的类型可分为以下几种: 序号 类型与描述 ...

  8. D-query SPOJ - DQUERY(模板莫队)

    题意: 给定一个序列,询问m次,每次求出区间 [ L,R ] 有多少个不同数字. 套模板就好了...但我不大明白....我的写法为什么不行...唉... #include <iostream&g ...

  9. Digits of Factorial LightOJ - 1045(数学题?)

    原文地址: https://blog.csdn.net/fenghoumilin/article/details/52293910 题意:求 n 的阶乘在 base 进制下的位数,这里有一个简单的方法 ...

  10. Mybatis笔记三:MyBatis的API文档

    mybatis文档:http://www.mybatis.org/mybatis-3/zh/getting-started.html mybatis-spring文档:http://www.mybat ...