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. PAT 1053 住房空置率

    https://pintia.cn/problem-sets/994805260223102976/problems/994805273284165632 在不打扰居民的前提下,统计住房空置率的一种方 ...

  2. 虚拟机VMware中的CentOS字符界面和图形界面切换

    在虚拟机中安装CentOS后展示的界面是图形用户界面,想切换到命令模式,于是查了linux下切换模式的方法,可是按了ctrl+alt+f1.f2....f7都是没用,后来发现是因为按键冲突的原因 问题 ...

  3. oracle 3大范式 理解

    CREATE OR REPLACE PACKAGE pack3 AS FUNCTION fun_calc (num1 NUMBER ,num2 NUMBER ) RETURN number ; fun ...

  4. delphi ERP框架

    之前做c/s架构,接了有家装饰的一个ERP项目,做了一个ERP框架,现在转后端开发了,这些东西还是蛮怀念的,就开源出来吧,有需要的同学可以参考. https://github.com/qianlnk/ ...

  5. 使用 TClientDataSet(1)

    本例效果图: 代码文件: unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, ...

  6. tomcat 启动异常 EOFException: Unexpected end of ZLIB input stream

    EVERE: Exception fixing docBase for context [/agdis] java.io .EOFException: Unexpected end of ZLIB i ...

  7. jmeter 正则表达式提取

    引用名称:自己定义的变量名称,后续请求将要引用到的变量名,如填写的是:id,后面的引用方式是${id} 正则表达式:提取内容的正则表达式,相当于lr中的关联函数 [()     括起来的部分就是需要提 ...

  8. struts 类型转换

  9. vue element 新增、编辑类Dialog公用函数

    调用 <el-button type="primary" class="my-button" size="small" :loadin ...

  10. BibTex相关

    标签(空格分隔): 杂七杂八的问题 又到了写论文的高峰期(?)在BibTeX中添加参考文献时,发现选项很多,对一些称呼还是一脸懵逼..阿一古,也许是最后一次写论文了,还弄清楚的还是清楚一下吧~ [转自 ...