Description

Farmer John has secret message that he wants to hide from his cows; the message is a string of length at least 2 containing only the characters A..Z. To encrypt his message, FJ applies a sequence of "operations" to it, where an operation applied to a string S first shortens S by removing either some (but not all) of the initial characters or some (but not all) of the final characters from S, after which the original string S is attached either at the beginning or end. For example, a single operation to the string ABC could result in eight possible strings: AABC ABABC BCABC CABC ABCA ABCAB ABCBC ABCC Given the final encrypted string, please count the number of possible ways FJ could have produced this string using one or more repeated operations applied to some source string. Operations are treated as being distinct even if they give the same encryption of FJ's message. For example, there are four distinct separate ways to obtain AAA from AA. Print your answer out modulo 2014.

XYW和他的男人聊天的时候,不让DZY看见他们聊天内容,他们决定用以下方式给一个字符串加密:每次把这个字符串的一个非空前缀或者后缀(不能是这个字符串的本身)加到这个字符串的前面或者后面。比如ABC就可以加密成 AABC ABABC BCABC CABC ABCA ABCAB ABCBC ABCC。
现在DZY拿到一个字符串(长度至多100),已知这个字符串从一个长度最少为2的字符串经过了至少一次加密(可以多次),现在DZY想要知道有多少种加密方案可以加密得到当前的字符串(初始字符串不同或者操作序列不同都视为不同的方案,结合样例解释食用更佳)。请你输出方案数对2014取模的值。

Input

* Line 1: A single encrypted string of length at most 100.

Output

* Line 1: The number of ways FJ could have produced this string with one or more successive operations applied to some initial string of length at least 2, written out modulo 2014. If there are no such ways, output zero.

Sample Input

ABABA

Sample Output

8
OUTPUT DETAILS: Here are the different ways FJ could have produced ABABA:
1. Start with ABA -> AB+ABA
2. Start with ABA -> ABA+BA
3. Start with AB -> AB+A -> AB+ABA
4. Start with AB -> AB+A -> ABA+BA
5. Start with BA -> A+BA -> AB+ABA
6. Start with BA -> A+BA -> ABA+BA
7. Start with ABAB -> ABAB+A
8. Start with BABA -> A+BABA
 

 
记忆化搜索可过。
 

 
#include <iostream>
#include <cstdio>
#include <map>
#include <string>
#include <cstring>
using namespace std;
#define reg register
#define mod 2014
string str;
int n;
map <string, int> f; int dp(string s)
{
if (f.find(s) != f.end()) return f[s];
int L = s.length();
int res = ;
for (reg int l = ; l * < L ; l ++)
{
if (s.substr(, l) == s.substr(l, l)) res = (res + dp(s.substr(l, L - l))) % mod;
if (s.substr(, l) == s.substr(L - l, l)) res = (res + dp(s.substr(l, L - l))) % mod;
if (s.substr(L - l, l) == s.substr(, l)) res = (res + dp(s.substr(, L - l))) % mod;
if (s.substr(L - l, l) == s.substr(L - l - l, l)) res = (res + dp(s.substr(, L - l))) % mod;
}
return f[s] = res;
} int main()
{
cin >> str;
printf("%d\n", (dp(str) - + mod) % mod);
return ;
}

[BZOJ3449] [Usaco2014 Feb]Secret Code的更多相关文章

  1. Android Secret Code

    我们很多人应该都做过这样的操作,打开拨号键盘输入*#*#4636#*#*等字符就会弹出一个界面显示手机相关的一些信息,这个功能在Android中被称为android secret code,除了这些系 ...

  2. hdu.1111.Secret Code(dfs + 秦九韶算法)

    Secret Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  3. Android 编程下的 Secret Code

    我们很多人应该都做过这样的操作,打开拨号键盘输入 *#*#4636#*#* 等字符就会弹出一个界面显示手机相关的一些信息,这个功能在 Android 中被称为 Android Secret Code, ...

  4. The secret code

    The secret code Input file: stdinOutput file: stTime limit: 1 sec Memory limit: 256 MbAfter returnin ...

  5. [swustoj 679] Secret Code

    Secret Code 问题描述 The Sarcophagus itself is locked by a secret numerical code. When somebody wants to ...

  6. BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )

    水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ------------------- ...

  7. 洛谷 P3102 [USACO14FEB]秘密代码Secret Code 解题报告

    P3102 [USACO14FEB]秘密代码Secret Code 题目描述 Farmer John has secret message that he wants to hide from his ...

  8. HDU 1111 Secret Code(数论的dfs)

    Secret Code Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  9. Secret Code

    Secret Code 一.题目 [NOIP模拟赛A10]Secret Code 时间限制: 1 Sec  内存限制: 128 MB 提交: 10  解决: 6 [提交][状态][讨论版] 题目描述 ...

随机推荐

  1. LeetCode第七题

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Have you ...

  2. Docker Compose基本使用-使用Compose启动Tomcat为例

    场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...

  3. Winform中自定义xml配置文件,并配置获取文件路径

    场景 在Winform程序中,需要将一些配置项存到配置文件中,这时就需要自定义xml的配置文件格式.并在一些工具类中去获取配置文件的路径并加载其内容. 关注公众号霸道的程序猿获取编程相关电子书.教程推 ...

  4. php接受的post数据类型

    通常情况下用户使用浏览器网页表单向服务器post提交数据,我们使用PHP的$_POST接收用户POST到服务器的数据,并进行适当的处理.但有些情况下,如用户使用客户端软件向服务端php程序发送post ...

  5. 【linux】【elasticsearch】docker部署elasticsearch及elasticsearch-head

    前言 Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎.无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进.性能最好的.功能最全的搜索引擎库.但是,Lu ...

  6. 关闭vue的eslint代码检测和WebStorm的代码检测

    1. 在vue项目中 bulid > webpack.base.conf.js 中: 如图,在rules规则中有一条规则是校验代码的,也就是红框2那行,要取消可以直接注释掉这行,或者把红框1的函 ...

  7. 讨厌的Permission denied:adb访问手机目录时,怎么处理Permission denied问题

    故事背景 手机某app出现了无响应,我想找到手机anr日志 但我只知道在data目录的某个目录里有个tra**的文件里有anr日志 具体的我真忘了,所以想要进入data中用ls查看一下 结果就出现了讨 ...

  8. .NET生成漂亮桌面背景

    .NET生成漂亮桌面背景 一天,我朋友指着某某付费软件对我说,这个东西不错,每天生成一张桌面背景,还能学英语(放置名人名言和翻译)!我说,这东西搞不好我也能做,然后朋友说,"如果你搞出来了, ...

  9. Android组件化路由实践

    Android应用组件化各个组件页面之间要实现跳转使用路由是一个很好的选择.本文将实现一个比较轻量级的路由组件,主要涉及以下知识: Annotation (声明路由目标信息) AnnotationPr ...

  10. Git tag相关命令

    常见命令如下: // 查看标签,可加上参数-l(列表形式列出) -n(附加说明) git tag [-l -n] // 查看符合检索条件的标签 git tag -l .*.* // 查看对应标签状态 ...