20172018-acmicpc-southeastern-european-regional-programming-contest-seerc-2017-en A - Concerts
2024-08-23 21:35:21
题意就是给一个字母序列a,以及一个另外一个字母序列b,你需要b中找到字母序列a,并且要求对于在b中的字母序列a,每个单词都需要满足相应的距离
其实很简单,我们利用DP[i][j]代表a已经匹配i个位置,当前是在b串的j位置,这样我们很容易写出转移方程
dp[ i ] [ j ] +=dp[ i-1 ] [ j - time[ i ] -1]
dp[ i ] [ j ] +=dp[ i-1 ] [ j ]
第一个式子的意思是第 i 个位置匹配成功,是由第 i - 1匹配成功,并且减去a[i-1]所需要的时间,转移而来。
第二个式子是我们为了得到前面能满足的状态,需要把前面的状态保存起来。
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#define LL long long
const int maxx = 1e5+;
const int MOD =1e9+;
using namespace std;
int dp[][maxx];
int k,n;
int word[maxx];
char b[maxx];
char a[];
int main(){
while(~scanf("%d%d",&k,&n)){
for (int i=;i<=;i++){
scanf("%d",&word[i]);
}
scanf("%s",a+);
scanf("%s",b+);
for (int i=;i<=n;i++){
if (b[i]==a[]){
dp[][i]=;
}
}
for (int i=;i<=k;i++){
for (int j=;j<=n;j++){
if (a[i]==b[j]){
int t=a[i-]-'A'+;
if (j-word[t]->=)
dp[i][j]=(dp[i][j]+dp[i-][j-word[t]-])%MOD;
}
dp[i][j]=(dp[i][j]+dp[i][j-])%MOD;
}
}
LL ans=;
printf("%d\n",dp[k][n]);
}
return ;
}
/*
2 10
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
AB
ABBBBABBBB
*/
最新文章
- 转载:WinForm中播放声音的三种方法
- Spring事务管理
- PHP之function_handling 函数
- Windows 命令大全
- Oracle RAC 常用维护工具和命令
- VI使用的小白教程
- .Net 4.0 Convert Object to XDocument
- jQuery跳房子插件hopscotch
- spring quartz开发中使用demo
- 用CSS3实现无限循环的无缝滚动
- lesson - 4 Linux目录文件管理
- layui中进行form表单一些问题
- react源代码重点难点分析
- 2、阿里云ECS发送邮件到腾讯企业邮箱(ECS默认不开启25端口)
- [Swift]LeetCode19. 删除链表的倒数第N个节点 | Remove Nth Node From End of List
- log4j详细配置
- R-FCN:安装训练自己的数据
- netstat 查看端口命令
- java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)
- 时分秒倒计时的js实现
热门文章
- USACO 2.1.4
- 在centos 6.3系统下安装java、tomcat环境的方法与步骤(方法经过验证,可安装成功)
- MySQL数据库起步 linux安装(更新中...)
- Leetcode63.Unique Paths II不同路径2
- 【教程】5分钟在PAI算法市场发布自定义算法
- 函数的length属性
- 【JZOJ4461】【GDOI2016模拟4.21】灯塔 分治
- 【水滴石穿】ReactNativeDemo
- Linux之源码包
- 工程没有生成lib文件,只生成了dll文件