题意就是给一个字母序列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
*/

20172018-acmicpc-southeastern-european-regional-programming-contest-seerc-2017-en A - Concerts的更多相关文章

  1. 2017-2018 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2017)

    2017-2018 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2017) 全靠 wxh的博客 补完这套.wx ...

  2. 2017-2018 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2017) Solution

    A:Concerts 题意:给出一个串T, 一个串S,求串S中有多少个串T,可以重复,但是两个字符间的距离要满足给出的数据要求 思路:先顺序统计第一个T中的字符在S中有多少个,然后对于第二位的以及后面 ...

  3. 2018-2019 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2018)

    layout: post title: 2018-2019 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 201 ...

  4. 2018-2019 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2018) Solution

    A. Numbers Unsolved. B. Broken Watch Solved. 题意: 一个圆盘上,有等分的n块区域,有三根指针,当三根指针分别位于两块区域的交界处时 指针的三点相连会形成一 ...

  5. 2016-2017 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2016)

    题目链接  Codefores_Gym_101164 Solved  6/11 Penalty Problem A Problem B Problem C Problem D Problem E Pr ...

  6. 2017-2018 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2017)

    A. Cakey McCakeFace 按题意模拟即可. #include<stdio.h> #include<iostream> #include<string.h&g ...

  7. 训练20191007 2017-2018 ACM-ICPC Latin American Regional Programming Contest

    2017-2018 ACM-ICPC Latin American Regional Programming Contest 试题地址:http://codeforces.com/gym/101889 ...

  8. 2017-2018 ACM-ICPC Latin American Regional Programming Contest PART (11/13)

    $$2017-2018\ ACM-ICPC\ Latin\ American\ Regional\ Programming\ Contest$$ \(A.Arranging\ tiles\) \(B. ...

  9. 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016)

    A. Within Arm's Reach 留坑. B. Bribing Eve 枚举经过$1$号点的所有直线,统计直线右侧的点数,旋转卡壳即可. 时间复杂度$O(n\log n)$. #includ ...

  10. 2016-2017 ACM-ICPC Northwestern European Regional Programming Contest (NWERC 2016)

    A. Arranging Hat $f[i][j]$表示保证前$i$个数字有序,修改了$j$次时第$i$个数字的最小值. 时间复杂度$O(n^3m)$. #include <bits/stdc+ ...

随机推荐

  1. Eular质数筛法

    小Hi:我们可以知道,任意一个正整数k,若k≥2,则k可以表示成若干个质数相乘的形式.Eratosthenes筛法中,在枚举k的每一个质因子时,我们都计算了一次k,从而造成了冗余.因此在改进算法中,只 ...

  2. Openlayers3 WebGis二次开发包实例

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs& ...

  3. pytorch 常用问题解决

    1.RuntimeError: cuda runtime erorr (77): an illegal memory access was encountered at 在使用命令前面加上CUDA_L ...

  4. 下载并安装Cent OS 6.5

    到官网下载centos 6.5指引 官网:https://www.centos.org/     [当然也可以通过百度搜索,然后打开] 进入官网,选择"Get CentOS Now" ...

  5. VS插件集合

    VS的强大不仅仅在于VS本身的强大. 同时,也有很多好用的插件,可以帮助我们更好的编辑代码, 提高效率. https://marketplace.visualstudio.com/search?tar ...

  6. !important覆写css行内样式

    <div class="block"> <span style="font-weight: bold; color: red;">Hel ...

  7. 2-3 Numpy+Matplotlib可视化(一)

    (1)pyplot基础绘图 # -*-coding:utf-8-*- # !/usr/bin/env python # Author:@vilicute import numpy as np impo ...

  8. [Vue CLI 3] 配置解析之 parallel

    官方文档中介绍过在 vue.config.js 文件中可以配置 parallel,作用如下: 是否为 Babel 或 TypeScript 使用 thread-loader. 该选项在系统的 CPU ...

  9. thinkphp---display与fetch区别

    区别: ① display方法直接输出模板文件渲染后的内容,fetch方法是返回模板文件渲染后的内容 ② 有时候我们不想直接输出模板内容,而是希望对内容再进行一些处理后输出, 就可以使用fetch方法 ...

  10. Spring_Bean的作用域---和使用外部属性文件

    <!-- 使用 bean的scope属性来配置bean的作用域 singleton:默认值.容器初始时创建bean实例,在整个容器的生命周期内只创建这一个bean单例 prototype:原型的 ...