P3102 [USACO14FEB]秘密代码Secret Code
题目描述
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.
农民约翰收到一条的消息,记该消息为长度至少为2,只由大写字母组成的字符串S,他通过一系列操作对S进行加密。
他的操作为,删除S的前面或者后面的若干个字符(但不删光整个S),并将剩下的部分连接到原字符串S的前面或者后面。如对于S=‘ABC’,共有8总可能的操作结果:
AABC
ABABC
BCABC
CABC
ABCA
ABCAB
ABCBC
ABCC
给出加密后的目标字符串,请计算共有多少种加密的方案。
对于同字符的字符串,加密方案不止一种,比如把AA加密成AAA,共有4种加密方案。将你的答案mod 2014后输出。
输入输出格式
输入格式:
- Line 1: A single encrypted string of length at most 100.
输出格式:
- 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.
输入输出样例
ABABA
8
说明
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
数据范围很小,可以暴力预处理出字符串中每个相同的部分,然后区间动规,枚举区间断点,累加将小段拼起来的方案。
/*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
char s[];
int len;
int dp[][];
bool f[][][];
void init(){
int i,j,k;
for(i=;i<=len;i++)
for(j=;j<=len;j++)
for(k=;i+k-<=len && j+k-<=len && s[i+k-]==s[j+k-];k++){
f[i][j][k]=;
}
return;
}
int main(){
scanf("%s",s+);
int i,j;
len=strlen(s+);
init();
for(i=;i<=len;i++)
for(j=i;j<=len;j++){
dp[i][j]=;
}
for(int step=;step<=len;step++){
for(i=;i+step-<=len;i++){
j=i+step-;
for(int k=;k*<step;k++){
if(f[i][i+k][k]) dp[i][j]=(dp[i][j]+dp[i+k][j])%;
if(f[i][j-k+][k]) dp[i][j]=(dp[i][j]+dp[i+k][j])%;
if(f[i][j-k+][k]) dp[i][j]=(dp[i][j]+dp[i][j-k])%;
if(f[j-*k+][j-k+][k]) dp[i][j]=(dp[i][j]+dp[i][j-k])%; }
}
}
printf("%d\n",dp[][len]-);
return ;
}
P3102 [USACO14FEB]秘密代码Secret Code的更多相关文章
- 洛谷 P3102 [USACO14FEB]秘密代码Secret Code 解题报告
P3102 [USACO14FEB]秘密代码Secret Code 题目描述 Farmer John has secret message that he wants to hide from his ...
- 洛谷P3102 [USACO14FEB]秘密代码Secret Code
P3102 [USACO14FEB]秘密代码Secret Code 题目描述 Farmer John has secret message that he wants to hide from his ...
- 洛谷 P3102 [USACO14FEB]秘密代码Secret Code
P3102 [USACO14FEB]秘密代码Secret Code 题目描述 Farmer John has secret message that he wants to hide from his ...
- 洛谷 P3102 [USACO14FEB]秘密代码Secret Code 【区间dp】
农民约翰收到一条的消息,记该消息为长度至少为2,只由大写字母组成的字符串S,他通过一系列操作对S进行加密. 他的操作为,删除S的前面或者后面的若干个字符(但不删光整个S),并将剩下的部分连接到原字符串 ...
- 洛谷P2922 [USACO008DEC] 秘密消息Secret Message [Trie树]
洛谷传送门,BZOJ传送门 秘密消息Secret Message Description 贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息. 信息是二进制的,共有M(1≤M≤5 ...
- Secret Code
Secret Code 一.题目 [NOIP模拟赛A10]Secret Code 时间限制: 1 Sec 内存限制: 128 MB 提交: 10 解决: 6 [提交][状态][讨论版] 题目描述 ...
- 「USACO08DEC」「LuoguP2922」秘密消息Secret Message(AC自动机
题目描述 Bessie is leading the cows in an attempt to escape! To do this, the cows are sending secret bin ...
- 洛谷p2922[USACO08DEC]秘密消息Secret Message
题目: 题目链接:[USACO08DEC]秘密消息Secret Message 题意: 给定n条01信息和m条01密码,对于每一条密码A,求所有信息中包含它的信息条数和被它包含的信息条数的和. 分析: ...
- 代码的坏味道(14)——重复代码(Duplicate Code)
坏味道--重复代码(Duplicate Code) 重复代码堪称为代码坏味道之首.消除重复代码总是有利无害的. 特征 两个代码片段看上去几乎一样. 问题原因 重复代码通常发生在多个程序员同时在同一程序 ...
随机推荐
- codeforces Gym 100338F Spam Filter 垃圾邮件过滤器(模拟,实现)
阅读题, 概要:给出垃圾邮件和非垃圾邮件的集合,然后按照题目给出的贝叶斯公式计算概率一封邮件是垃圾邮件的概率. 逐个单词判断,将公式化简一下就是在垃圾邮件中出现的次数和在总次数的比值,大于二分之一就算 ...
- vue的使用-项目总结
1,这是一个重前端逻辑,轻交互,数据展示的项目,可读性差,2,组件划分的坑,复用过多的坑,复用过多导致要在js手动判断太多东西,不便于可读3,vuex的坑,数据分为后台请求数据的暂存,前端页面逻辑的状 ...
- 8 Java 归并排序(MergerSort)
图片素材与文字描述来自:尚硅谷-韩顺平数据结构与算法. 1.基本思想 归并排序是利用归并的思想实现的排序方法,该算法采用经典的分治(divide-and-conquer)策略(分治法将问题分(divi ...
- shell脚本,计算1+3+5....100等于多少?
[root@localhost wyb]# cat unevenjia.sh #!/bin/bash #从1+++...100的结果 i= count=$1 $count` do sum=$(($su ...
- js中的跨域方法总结
什么是跨域? 浏览器的安全策略,只要协议,域名,端口有任何一个不同,就被当做不同的域. 下面对http://www.qichedaquan.com的同源检测 http://www.qichedaqua ...
- OpenCV2.4.11+VS2012的环境配置+“fatal error LNK1112: 模块计算机类型“X86”与目标计算机类型“x64”冲突”的问题解决
本来OpenCV环境配置的问题是个基础问题,但是步骤有点小烦,所以几乎每次都要百度一下,加上这次遇到的“fatal error LNK1112: 模块计算机类型“X86”与目标计算机类型“x64”冲突 ...
- centos7系统root无法通过su切换到某个普通用户
[root@test ~]# su webappsu: failed to execute /bin/bash: Resource temporarily unavailable [root@test ...
- [php] 高级教程
include 和 require 语句用于在执行流中插入写在其他文件中的有用的代码. include 和 require 除了处理错误的方式不同之外,在其他方面都是相同的: require 生成一个 ...
- python 实现计算器功能 输入字符串,输出相应结果
import re formul='1 - 2 *( (6 0- 30+(0-40/5) * (9-2* 5/3 +7 /3*99/4*2998 +10 *568/14)) - (-4*3) / (1 ...
- C#学习基础概念二十五问
C#学习基础概念二十五问 1.静态变量和非静态变量的区别?2.const 和 static readonly 区别?3.extern 是什么意思?4.abstract 是什么意思?5.internal ...