[BZOJ3449] [Usaco2014 Feb]Secret Code
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.
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
Sample Output
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的更多相关文章
- Android Secret Code
我们很多人应该都做过这样的操作,打开拨号键盘输入*#*#4636#*#*等字符就会弹出一个界面显示手机相关的一些信息,这个功能在Android中被称为android secret code,除了这些系 ...
- hdu.1111.Secret Code(dfs + 秦九韶算法)
Secret Code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- Android 编程下的 Secret Code
我们很多人应该都做过这样的操作,打开拨号键盘输入 *#*#4636#*#* 等字符就会弹出一个界面显示手机相关的一些信息,这个功能在 Android 中被称为 Android Secret Code, ...
- The secret code
The secret code Input file: stdinOutput file: stTime limit: 1 sec Memory limit: 256 MbAfter returnin ...
- [swustoj 679] Secret Code
Secret Code 问题描述 The Sarcophagus itself is locked by a secret numerical code. When somebody wants to ...
- BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )
水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ------------------- ...
- 洛谷 P3102 [USACO14FEB]秘密代码Secret Code 解题报告
P3102 [USACO14FEB]秘密代码Secret Code 题目描述 Farmer John has secret message that he wants to hide from his ...
- HDU 1111 Secret Code(数论的dfs)
Secret Code Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- Secret Code
Secret Code 一.题目 [NOIP模拟赛A10]Secret Code 时间限制: 1 Sec 内存限制: 128 MB 提交: 10 解决: 6 [提交][状态][讨论版] 题目描述 ...
随机推荐
- DBCP
DBCP(DataBase Connection Pool)数据库连接池,由Apache公司开发.连接池的运用避免了反复建立连接造成的资源浪费,预先建立一些连接放在数据库连接池中,需要时取出,不需要时 ...
- Elastic Stack 笔记(八)Elasticsearch5.6 Java API
博客地址:http://www.moonxy.com 一.前言 Elasticsearch 底层依赖于 Lucene 库,而 Lucene 库完全是 Java 编写的,前面的文章都是发送的 RESTf ...
- Day 18 软件管理3之搭建网络仓库
搭建一个网络仓库 服务端: 10.0.0.200 1.准备软件包( 1.光盘 2.缓存 3.联网下载 4.同步 ) 2.通过p共享软件包存放的目录 3.将光盘中的软件包都拷贝至p的共享目录下 4. ...
- C# 代码往oracle数据库添加datetime格式列
C# 代码往oracle数据库添加datetime格式列时,不需要在insert语句中为datetime类型使用to_date函数
- Linux系统在开机的时候自动启动SVN
Linux系统在开机的时候自动启动SVN 1.创建执行脚本svn.sh(/root路径下,随便哪个路径),其内容很简单,如下: #!/bin/bash svnserve -d --listen ...
- XSS攻击-原理学习
本文优先发布于简书https://www.jianshu.com/p/04e0f8971890 1.百度百科XSS,跨站脚本攻击(Cross Site Scripting)缩写为CSS,但这会与层叠样 ...
- 如何快速转载CSDN中的博客
看到一篇<如何快速转载CSDN中的博客>,介绍通过检查元素→复制html来实现快速转载博客的方法.不过,不知道是我没有领会其精神还是其他原因,测试结果为失败.
- 【django】ajax,上传文件,图片预览
1.ajax 概述: AJAX = 异步 JavaScript 和 XML. AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味 ...
- @Data注解getset不起作用
在idea的setting安装Lombok插件,重启idea
- Mysql INSTR函数
在Mysql中,可以使用INSTR(str,substr)函数,用于在一个字符串(str)中搜索指定的字符(substr),返回找到指定的字符的第一个位置(index),index是从1开始计算,如果 ...