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. charles 禁用Cookies /Block Cookies Settings

    本文参考:charles 禁用Cookies 禁用cookies/Block Cookies Settings 功能:阻止发送和接收Cookie 禁用Cookie工具 禁用Cookie工具阻止发送和接 ...

  2. PTA A1001&A1002

    从今天起每天刷1-2题PAT甲级 第一天 A1001 A+B Format (20 分) 题目内容 Calculate a+b and output the sum in standard forma ...

  3. 深入全面理解面向对象的 JavaScript

    深入全面理解面向对象的 JavaScript (原著: 曾 滢, 软件工程师, IBM,2013 年 4 月 17 日) JavaScript 函数式脚本语言特性以及其看似随意的编写风格,导致长期以来 ...

  4. docker部署jenkins

    步骤一: 查找jenkins镜像(也可以直接去jenkins官网找镜像docker pull jenkins/jenkins)(官方版本文档https://hub.docker.com/_/jenki ...

  5. python,json解析字符串时ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

    今天写测试工具的时候,去excel取数据,用json解析字符串为字典时报错,后经调试,发现是单引号的原因,将单引号换位双引号即可 def getExcelValue_to_dic(filepath): ...

  6. IDEA加密算法(含所需jar包(commons-codec-1.11.jar ,bcprov-jdk15on-160.jar))

    软件设计上机实验IDEA算法: import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.Se ...

  7. C++进程间通讯方式

    1.剪切板模式. 在MFC里新建两个文本框和两个按钮,点击发送按钮相当于复制文本框1的内容,点击接收按钮相当于粘贴到文本框2内: 发送和接收按钮处功能实现如下: void CClipboard2Dlg ...

  8. 报错:ORA-25150:不允许对区参数执行ALERING

    alter table 表名 MOVE   storage   (     next 128   ) ; -- Add/modify columns alter table 表名 add 列名 var ...

  9. [python]泡菜存储(pickle)

    对于保存文本,如果要保存的数据像列表,字典甚至是类的实例时,普通的文件操作就会很复杂,如果把这些转化为字符串写入到文本文件中保存,把这个过程反过来读取的话就会异常麻烦,因此python提供了一个标准模 ...

  10. java项目打包

    http://blog.csdn.net/qq_34845382/article/details/53885907 自己用Rinnable JAR file 方法也可以.更简单.直接点击Finish即 ...