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.

输入输出样例

输入样例#1:

ABABA
输出样例#1:

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
#include<iostream>
#include<cstdio>
#include<cstring>
#define mod 23333333
using namespace std;
int ans;
char s[],c[],ss[];
bool vis[];
int Hash(char ch[],int len){
int res=;
for(int i=;i<=len;i++)
res=(res*+(ch[i]-'A'+))%mod;
return res;
}
int main(){
scanf("%s",s+);
int len=strlen(s+);
vis[Hash(s,len)]=;
int now;
for(int i=;i<len;i++){//枚举剪下来的字符串的长度
//从前面剪
//接到后面
for(int k=;k<=len;k++)ss[k]=s[k];
for(int k=;k<=i;k++)ss[len+k]=s[k];
now=Hash(ss,len+i);
if(!vis[now]){
vis[now]=;
ans++;
if(ans>=)ans-=;
}
//接到前面
for(int k=;k<=i;k++)ss[k]=s[k];
for(int k=;k<=len;k++)ss[k+i]=s[k];
now=Hash(ss,len+i);
if(!vis[now]){
vis[now]=;
ans++;if(ans>=)ans-=;
}
//从后面剪
//接到后面
for(int k=;k<=len;k++)ss[k]=s[k];
for(int k=,j=len;k<=i;k++,j--)ss[len+k]=s[j];
now=Hash(ss,len+i);
if(!vis[now]){
vis[now]=;
ans++;if(ans>=)ans-=;
}
//接到前面
for(int k=,j=len;k<=i;k++,j--)ss[k]=s[j];
for(int k=;k<=len;k++)ss[k+i]=s[k];
now=Hash(ss,len+i);
if(!vis[now]){
vis[now]=;
ans++;if(ans>=)ans-=;
}
}
printf("%d",ans);
}

20分 不知道为啥写的哈希wa了

/*
substr是C++语言函数,主要功能是复制子字符串,要求从指定位置开始,并具有指定的长度。
*/
#include<bits/stdc++.h>
using namespace std;
string s;
map<string,int>f;
int find(string x){
if(f[x]!=)return f[x];
int tmp=;
int l=x.size();
for(int i=;i*<l;i++){
if(x.substr(,i)==x.substr(l-i,i))
tmp+=find(x.substr(i,l-i))+find(x.substr(,l-i));
if(x.substr(,i)==x.substr(i,i))
tmp+=find(x.substr(i,l-i));
if(x.substr(l-*i,i)==x.substr(l-i,i))
tmp+=find(x.substr(,l-i));
}
return f[x]=tmp%;
}
int main(){
cin>>s;
cout<<(find(s)+-)%;
return ;
}

100分 STL+记忆化搜索

 

洛谷P3102 [USACO14FEB]秘密代码Secret Code的更多相关文章

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

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

  2. 洛谷 P3102 [USACO14FEB]秘密代码Secret Code

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

  3. 洛谷 P3102 [USACO14FEB]秘密代码Secret Code 【区间dp】

    农民约翰收到一条的消息,记该消息为长度至少为2,只由大写字母组成的字符串S,他通过一系列操作对S进行加密. 他的操作为,删除S的前面或者后面的若干个字符(但不删光整个S),并将剩下的部分连接到原字符串 ...

  4. P3102 [USACO14FEB]秘密代码Secret Code

    题目描述 Farmer John has secret message that he wants to hide from his cows; the message is a string of ...

  5. 洛谷P2922 [USACO008DEC] 秘密消息Secret Message [Trie树]

    洛谷传送门,BZOJ传送门 秘密消息Secret Message Description     贝茜正在领导奶牛们逃跑.为了联络,奶牛们互相发送秘密信息.     信息是二进制的,共有M(1≤M≤5 ...

  6. 洛谷p2922[USACO08DEC]秘密消息Secret Message

    题目: 题目链接:[USACO08DEC]秘密消息Secret Message 题意: 给定n条01信息和m条01密码,对于每一条密码A,求所有信息中包含它的信息条数和被它包含的信息条数的和. 分析: ...

  7. 洛谷 P2922 [USACO08DEC]秘密消息Secret Message

    题目描述 Bessie is leading the cows in an attempt to escape! To do this, the cows are sending secret bin ...

  8. 洛谷【P3612】[USACO17JAN]Secret Cow Code秘密奶牛码

    我对分治的理解:https://www.cnblogs.com/AKMer/p/9728574.html 题目传送门:https://www.luogu.org/problemnew/show/P36 ...

  9. 洛谷——P2176 [USACO14FEB]路障Roadblock

    P2176 [USACO14FEB]路障Roadblock 题目描述 每天早晨,FJ从家中穿过农场走到牛棚.农场由 N 块农田组成,农田通过 M 条双向道路连接,每条路有一定长度.FJ 的房子在 1 ...

随机推荐

  1. 谈String,StringBuilder,StringBuffer随笔

    一.谈谈三者在实现上的区别.   (1)先看String 方法,实现了Serializable, Comparable, CharSequence三个接口 package java.lang; imp ...

  2. python suds 调用webservice 缓存

    在linux系统中 如果webservice更新了字段 suds调用有可能缓存以前的字段或方法,对新的字段报找不到类型 TypeNotFound,或者对 新加的方法找不到该方法的错误. 当更新或添加w ...

  3. IP通信中音频编解码技术与抗丢包技术概要

    此文较长,建议收藏起来看. 一.一个典型的IP通信模型 二.Server2Server技术分类 Server2Server这块也是一个专门的领域,这里只简单分个类. 1.同一国家相同运营商之间: 同一 ...

  4. @@cursor_rows变量解析

    刚刚看了@@curosr_rows这个全局变量,发现这个变量挺有意思.要懂得这个变量的意义,基本上牵扯到cursor一些比较容易忽视的内容. @@cursor_rows是用来记录当前游标的数量,也就从 ...

  5. 比线程更NB的存在

    阅读目录 一 引子 二 协程介绍 三 Greenlet模块 四 Gevent模块 引子 之前我们学习了线程.进程的概念,了解了在操作系统中进程是资源分配的最小单位,线程是CPU调度的最小单位.按道理来 ...

  6. 洛谷【P3407】散步

    我对状态空间的理解:https://www.cnblogs.com/AKMer/p/9622590.html 题目传送门:https://www.luogu.org/problemnew/show/P ...

  7. 报错之-Cannot set property 'onclick' of null

    当js文件放在head里面时,如果绑定了onclick或者onmouseover事件,就会出现如下图类似的错误,是因为浏览器的加载你写的html文档的顺序是从上往下,加载完按钮节点才执行的js,所以当 ...

  8. netty中的Channel、ChannelPipeline

    一.Channel与ChannelPipeline关系 每一个新创建的 Channel 都将会被分配一个新的 ChannelPipeline.这项关联是永久性 的:Channel 既不能附加另外一个 ...

  9. JS中数组方法小总结

    1.array.concat(item……) 返回:一个新数组 该方法产生一个新数组,它包含一份array的浅复制,并把一个或多个参数item附加在其后.如果参数item是一个数组,那么它的每个元素会 ...

  10. PopupWindow 防微信弹出右 侧窗体(继承PopupWindow )

    1, pop自定义 public class SelectPicPopupWindow extends PopupWindow { private Button btn_take_photo, btn ...