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. cxGrid 单元格回车移到下一行,当移到最后一个单元格时回车新增一行【转】

    1 在TcxGridDBTableView中,设定属性 NewItemRow.Visible = True 2 在cxgrid中输入数据怎样回车换行  在TcxGridDBTableView中  将属 ...

  2. Error: Unable to access jarfile D:\Apache\apache-jmeter-3.0\bin\ApacheJMete.jar

    双击jmeter.bat后,在cmd窗口显示Error: Unable to access jarfile D:\Apache\apache-jmeter-3.0\bin\ApacheJMete.ja ...

  3. Support for SSL/TLS protocols on Windows

    https://blogs.msdn.microsoft.com/kaushal/2011/10/02/support-for-ssltls-protocols-on-windows/ Support ...

  4. vue 大概流程(未完)

    规划组件结构 编写对应路由 具体写每个组件功能

  5. rocketmq 主机负载异常飙高问题的解决

    最近在部署rocketmq到物理机时, 发现并解决了一个主机Load异常飙高的问题, 觉得有必要记录一下. 我们采用了rocketmq(https://github.com/alibaba/Rocke ...

  6. 在输入密码框中眼睛睁开可以看见数字,眼睛闭上看不见数字怎么用JS实现

    无论做那个项目,登录注册页面总是避免不了的,那怎么用js来控制密码的显示和隐藏呢?先看一下效果图: HTML代码如下: <div>         <label for=" ...

  7. Lottie开源库实现Android动画效果

    Lottie简介 Lottie是一个支持Android.iOS.React Native,并由Adobe After Effects制作aep格式的动画,然后经由bodymovin插件转化渲染为jso ...

  8. sqlserver查询数据库中包含某个字段的所有表和所有存储过程

    1.查询包含某字段的所有表 select object_name(id) objName,Name as colName from syscolumns where (name like'%你要查询的 ...

  9. hdu 3307 简单的指数循环节

    #include<stdio.h>#include<string.h>#include<algorithm>#define LL __int64using name ...

  10. 【刷题】BZOJ 2693 jzptab

    Description Input 一个正整数T表示数据组数 接下来T行 每行两个正整数 表示N.M Output T行 每行一个整数 表示第i组数据的结果 Sample Input 1 4 5 Sa ...