每段可以连续的串的可能性是个Fibonacci数列   但是直接dp更好吧~~

#include <cstdio>
#include <cstring> using namespace std; char a[5010];
int main()
{
while(scanf("%s",a) && strcmp(a, "0"))
{
int len = strlen(a), cur = 1;
int b = a[0] - '0';
unsigned long long k = 1;
for(int i = 1; i < len; i++)
{
if(a[i] == '0')
{
b *= 10;
}
else if(a[i] - '0' + b*10 <= 26)
{
if(a[i+1] != '0')
cur++;
b = a[i] - '0';
}
else
{
unsigned long long d1 = 1, d2 = 2;
if(cur >= 2)
{
for(int j = 2; j < cur; j++)
{
d2 += d1;
d1 = d2 - d1;
}
k *= d2;
}
cur = 1;
b = a[i] - '0';
}
}
if(cur >= 2)
{
unsigned long long d1 = 1, d2 = 2;
for(int j = 2; j < cur; j++)
{
d2 += d1;
d1 = d2 - d1;
}
k *= d2;
}
printf("%llu\n",k);
}
return 0;
}

转一个DP的

#include <stdio.h>
#include <string.h>
#define LL long long
char s[5050];
LL d[5050];
int main()
{
while(scanf("%s",s)==1)
{
int l=strlen(s);
if(l==1&&s[0]=='0')break;
memset(d,0,sizeof(d));
d[0]=1;
for(int i=1;i<=l;i++)
{
if(s[i-1]!='0')
d[i]=d[i-1];
if(i>1&&((s[i-2]=='1'&&s[i-1]>='0')||(s[i-2]=='2'&&s[i-1]<='6'&&s[i-1]>='0')))
{
d[i]+=d[i-2];
}
}
printf("%lld\n",d[l]);
}
return 0;
}

spoj 394的更多相关文章

  1. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  2. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  3. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  4. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

  5. SPOJ bsubstr

    题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...

  6. 【SPOJ 7258】Lexicographical Substring Search

    http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...

  7. 【SPOJ 1812】Longest Common Substring II

    http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...

  8. 【SPOJ 8222】Substrings

    http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求 ...

  9. SPOJ GSS2 Can you answer these queries II

    Time Limit: 1000MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description Being a ...

随机推荐

  1. ORACLE字符串分组聚合函数(字符串连接聚合函数)

    ORACLE字符串连接分组串聚函数 wmsys.wm_concat SQL代码: select grp, wmsys.wm_concat(str) grp, 'a1' str from dual un ...

  2. Unity3d-UI插件EZGUI官方视频教程

    Showcase Teaser (D/L) – Showcases some of the things that can be accomplished using EZ GUI.#1 – Butt ...

  3. sql2005导出数据字典

    右击要导出的数据库,点击 新建视图 粘贴下面代码 SELECT 表名= then d.name else '' end, 表说明= then isnull(f.value,'') else '' en ...

  4. 使用Win7+IIS7发布网站或服务步骤

    1.安装IIS服务:控制面板=>程序=>打开或关闭WINDOWS 功能=>Internet 信息服务=>WEB服务管理器全选√ 和万维网服务:应用程序开发功能: 2.打开IIS ...

  5. poi-3.11-beta2-20140822.jar操作excel方法

    poi-3.11-beta2-20140822.jar操作excel方法 根据不同类型读取值的方法: // 获取单元格内不同类型的值 public String getValueByType(HSSF ...

  6. Swift调用Objective-C

    Swift调用Objective-C需要一个名为“<工程名>-Bridging-Header.h”的桥接头文件,如下图所示.桥接头文件的作用是为Swift调用Objective-C对象搭建 ...

  7. Cocos2d-x实例:设置背景音乐与音效-设置场景实现

    设置场景(Setting),Setting.h文件代码如下: #ifndef __Setting_SCENE_H__ #define __Setting_SCENE_H__ #include &quo ...

  8. Objective-C(iOS)严格单例模式正确实现

    注:本文所有权归作者所有,转载请注明出处 当希望在一个应用程序中某个类的对象只能存在一个的时候就可以考虑用单例模式来实现,单例模式在C++中比较容易实现(只需把构造函数声明为private),而在Ob ...

  9. 在windows7中使用计划任务命令SCHTASKS查询计划任务失败的解决方案

    造成这种原因是因为编码问题: 因此需要修改编码:chcp schtasks.exe /query 会报错     错误: 无法加载列资源. 修改编码为936为436就可以允许啦,但是中文不不能显示啦. ...

  10. 函数 sort,unique,stable_sort,count_if,谓词

    bool isShorter(const string &s1,const string &s2) { return s1.size() < s2.size(); } bool ...