poj 2033 Alphacode
来源:互联网 发布:淘宝达人账号简介 编辑:程序博客网 时间:2024/05/16 06:09
简单DP,里面是有0的,把0区分清楚就可以A掉了,还有个需要注意的,这个数组开1000会运行错误,最好大点开。
题意:1……26表示A到Z,因为11可以有AA和K2种意思,所以要你求给你的这个译码的原文可能有多少种。
思路:还是跟上面说的一样,主要是区分这个0的存在和26这个介值。
看代码吧,我相信还算是清晰。
#include<cstdio>#include<cstring>#include<iostream>#define N 50001#define max(a1,b1) (a1)>(b1)?(a1):(b1)using namespace std;char str[N];long long dp[N],len;int main(void){ while(scanf("%s",str+1)!=EOF) { len = strlen(str+1); if(len==1&&str[1]=='0') break; dp[0] = 1; dp[1] = 1; for(int i=2;i<=len;++i) { int x = str[i-1]-'0'; int y = str[i] - '0'; x *= 10; x += y; if(y==0) { dp[i] = dp[i-2]; } else if(x<=10) { dp[i] = dp[i-1]; } else if(x<=26) { dp[i] = dp[i-2]+dp[i-1]; } else { dp[i] = dp[i-1]; } } cout<<dp[len]<<endl; } return 0;}
- POJ 2033 Alphacode
- poj 2033 Alphacode
- poj 2033 Alphacode
- poj 2033 Alphacode
- poj 2033 Alphacode
- POJ 2033 Alphacode 笔记
- poj 2033 : Alphacode(DP)
- POJ 2033 Alphacode(26编码,水题)
- AOJ-AHU-OJ-36 (POJ-2033) Alphacode
- POJ 2033|SPOJ ACODE|Alphacode|动态规划
- Alphacode
- Alphacode
- 1001: Alphacode
- 1001. Alphacode
- poj2033------Alphacode
- Sicily1001 Alphacode
- C++ Alphacode
- SPOJ Alphacode
- 黑马程序员——GUI
- [自学问题总结]静态成员和非静态成员的区别
- struts2类型转换
- struts2标签不显示Label属性
- jsp自定义标签
- poj 2033 Alphacode
- Filter与Servlet的区别
- struts2 Action访问Servlet Api
- oracle使用汉字首字母查询函数
- IFrame下父页面调用子页面的JS方法
- 去除空格的js 和 使用正…
- Apache遇到的问题:APR not found、APR-util not found 、pcre-config for libpcre not found. PCRE is required
- web.xml;context-param;init-param
- 常用正则表达式(程序员必转)