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

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<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mod 2014
using namespace std;
char s[120];
int dp[120][120],f[120][120][120];
int main(){scanf("%s",s+1);int len=strlen(s+1);for(int i=1;i<=len;i++)for(int j=1;j<=len;j++)for(int k=1;i+k-1<=len&&j+k-1<=len&&s[i+k-1]==s[j+k-1];k++)f[i][j][k]=1;for(int i=1;i<=len;i++)for(int j=1;j<=len;j++)dp[i][j]=1;for(int l=2;l<=len;l++)for(int i=1;i+l-1<=len;i++){int j=i+l-1;for(int k=1;k*2<l;k++){if(f[i][i+k][k])    dp[i][j]=(dp[i][j]+dp[i+k][j])%mod;if(f[i][j-k+1][k])    dp[i][j]=(dp[i][j]+dp[i+k][j])%mod;if(f[i][j-k+1][k])    dp[i][j]=(dp[i][j]+dp[i][j-k])%mod;if(f[j-2*k+1][j-k+1][k])    dp[i][j]=(dp[i][j]+dp[i][j-k])%mod;}}cout<<dp[1][len]-1;        
}

 

转载于:https://www.cnblogs.com/cangT-Tlan/p/7569629.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/415804.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

iview tag 标签点击事件

iview的tag组件有一个地方比较奇怪&#xff0c;就是默认只有on-close事件。 当我们想点击关闭和激活tag组件的时候&#xff0c;我们只能自己进行维护。 需要只用click.native进行控制 <Tag color"red" :checkable"true" :checked"false" clic…

android 获取url中的参数,验证邮箱格式,截取字符串中键值对的值,String的字节长度,去空格,替换字符

String ss"hello"; byte[] buffss.getBytes(); int fbuff.length; System.out.println(f); 字节长度。一个中文是3。其他是1 1、获取url中的参数 创建string String urls "http://www.yxtribe.com/yuanxinbuluo/weixin/getJsp?urlwechatweb/business-style-f…

oracle数据导入与导出

数据的导入导出 说明&#xff1a; 针对的对象&#xff1a; 数据的导入导出牵涉到的角色主要是工程实施人员。 需解决的问题&#xff1a;把所需要的数据从一个数据库中导入到另外一个数据库中。 1 工具方式 1.1 工具说明 1. 使用PLSQL Developer工具主要为了…

ubuntu中使用apt-get安装zbar

apt-get是linux中常用的shell命令&#xff0c;适用于deb包管理式的操作系统&#xff0c;主要用于自动从互联网的软件仓库中搜索、安装、升级、卸载软件或操作系统。apt-get命令一般需要root权限执行&#xff0c;所以前边一般跟着sudo命令。 Zbar是一个开源的二维码&#xff08;…

微信红包 开发前的准备

今天的开发目标是实现微信红包功能。先记录需要进行微信红包开发前的准备工作。 1、进行微信支付&#xff1a;需要注册认证的服务号或者认证的企业号 2、若要进行红包开发&#xff0c;前置准备条件 入住时间超过90天&#xff1b;连续交易正常交易时间30天&#xff1b; 3、微…

QC安装与运行中的问题汇集

服务器localhost127.0.0.1一、QC安装成功&#xff0c;但服务无法启动QC在安装过程中最容易出问题的就是SQL和jbossSQL ,JBOSS, QC三个启动都是独立的。托盘qc启动成功并不表示成功启动jboss,不加qcbin试试看&#xff0c;能确认jboss是否启动成功。如果JBOSS启动失败往往有以下几…

android 屏幕横竖屏切换时生命周期运行详解,创建横屏layout,has no declaration in the base

横屏代码 1、配置文件设置 android:screenOrientation"landscape" 2、java代码设置 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//hp 竖屏代码 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);//sp activit…

CodeForces 580A Kefa and First Steps

Time limit 2000 ms Memory limit 262144 kB Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes ai money. Kefa loves progress, thats why he wants to know the length of…

微信支付 商户Key 支付Key API密钥 的获取

读了微信支付的开发文档&#xff0c;感觉是不同阶段&#xff0c;不同的同学写的&#xff0c;有些专业名词比较混乱&#xff0c;甚至还会有错别字&#xff0c;以及接口更新了&#xff0c;而文档不更新的情况。 使用微信支付&#xff0c;必须要用到 api密钥进行签名 其中 &…

oracle 10g 报错:ORA-00257: archiver error. Connect internal only, until freed

今天在公司&#xff0c;突然同事告诉我数据库无法登录了&#xff0c;想想这段时间没有动过库&#xff0c;为什么无法登录呢&#xff1f;一边想是什么问题&#xff0c;一边连接测试登录。 首先报错&#xff1a;ORA-00257: archiver error. Connect internal only, until freed.…

android 获取键盘回车键事件,设置软键盘回车键显示内容,点击空白处隐藏软键盘

首先设置EditText的回车属性 drawable文件 drawable/editcolor <?xml version"1.0" encoding"utf-8"?> <shape xmlns:android"http://schemas.android.com/apk/res/android" android:shape"rectangle"><size andro…

微信支付 签名算法 sign node实现

开发微信支付过程中&#xff0c;第一道门槛就是微信支付接口签名&#xff0c;只要按照官方文档写&#xff0c;就不会有什么错。 1、官方签名文档地址 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter4_3 2、我的实现 // 获取微信签名 getSign: (para…

触发器定义

create trigger atf on dbo.a after insertasbegin truncate table aend转载于:https://www.cnblogs.com/huanglong1987/p/7587570.html

android RecyclerView EditText 取消自动聚焦

在manifest中的activity中配置 android:windowSoftInputMode"adjustPan"

使用WINPE在硬盘安装WIN7系统

使用WINPE在硬盘安装WIN7系统 看到此标题&#xff0c;可能好多朋友会说&#xff0c;安装个WIN7操作系统&#xff0c;使用安装盘直接安装就是了&#xff0c;有必要做个文章介绍吗&#xff1f;的确&#xff0c;安装操作系统&#xff0c;最方便最简单的方法&#xff0c;就是使用系…

微信开发基础 获取用户OpenID 列表

1、官方文档 https://mp.weixin.qq.com/wiki?tresource/res_main&idmp1421140840 2、我使用的请求库是superagent&#xff0c;核心代码如下 /*** 获取公众号用户OpenID列表* param {*} request * param {*} h */ userOpenIdList: async function (request, h) {const ac…