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. Yum未完成事务问题

    1.安装 yum-complete-transaction [root@linux-node1 ~]# yum -y install yum-utils 2.清除yum缓存 [root@linux-n ...

  2. 解析 HTTP 请求 header 错误

    1.org.apache.coyote.http11.Http11Processor.service 解析 HTTP 请求 header 错误 2.原因:在创建项目名称的时候,文件名不能带有中文,只能 ...

  3. Java第三次作业第二题

    2. [请复制本程序,作为java程序代码,进行编译,补充填写缺失代码部分,并实现题目要求功能,从而获得空白填写所需的内容.] 定义3个线程,模拟红绿灯的效果 一个线程控制画一个实心红圆 一个线程控制 ...

  4. python安装第三方包的安装路径, dist-packages和site-packages区别

    简单来说 如果是系统自带的python,会使用dist-packages目录 如果你手动安装python,它会直接使用目录site-packages 这允许你让两个安装隔离开来 dist-packag ...

  5. 【Sentinel】sentinel 集成 apollo 最佳实践

    [Sentinel]sentinel 集成 apollo 最佳实践 前言   在 sentinel 的控制台设置的规则信息默认都是存在内存当中的.所以无论你是重启了 sentinel 的客户端还是 s ...

  6. 在.NET Core中使用DispatchProxy“实现”非公开的接口

    原文地址:"Implementing" a non-public interface in .NET Core with DispatchProxy 原文作者:Filip W. 译 ...

  7. js中对时间的操作

    我们先来看一下如何获取当前时间: var date = new Date() //输出:Tue Jul 02 2019 10:36:22 GMT+0800 (中国标准时间) 紧接着,我们来获取相关参数 ...

  8. 基于 HTML5 和 WebGL 的地铁站 3D 可视化系统

    前言 工业互联网,物联网,可视化等名词在我们现在信息化的大背景下已经是耳熟能详,日常生活的交通,出行,吃穿等可能都可以用信息化的方式来为我们表达,在传统的可视化监控领域,一般都是基于 Web SCAD ...

  9. maven 打包构建相关命令

    1.命令 mvn clean package 依次执行clean.resources.compile.testResources.testCompile.test.jar(打包)等7个阶段. mvn ...

  10. Kafka 学习笔记之 High Level Consumer相关参数

    High Level Consumer相关参数 自动管理offset auto.commit.enable = true auto.commit.interval.ms = 60*1000 手动管理o ...