Concerts

题目描述

John enjoys listening to several bands, which we shall denote using A through Z. He wants to attend several concerts, so he sets out to learn their schedule for the upcoming season. 
He finds that in each of the following n days (1 ≤ n ≤ 1e5), there is exactly one concert. He decides to show up at exactly k concerts (1 ≤ k ≤ 300), in a given order, and he may decide to attend more than one concert of the same band.
However, some bands give more expensive concerts than others, so, after attending a concert given by band b, where b spans the letters A to Z, John decides to stay at home for at least hb days before attending any other concert.
Help John figure out how many ways are there in which he can schedule his attendance, in the desired order. Since this number can be very large, the result will be given modulo 1e9 + 7.

输入

The first line contains k and n. The second line contains the 26 hb values, separated by spaces.
The third line contains the sequence of k bands whose concerts John wants to attend e.g.,AFJAZ, meaning A, then F etc. The fourth line contains the schedule for the following n days,specified in an identical manner.

输出

The number of ways in which he can schedule his attendance (mod 1e9 + 7).

样例输入

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

样例输出

10

【题意】

定义S串,T串。分别是输入的第一个,第二个字符串。

给出26种音乐会,每次举行完必须要休息多少天。

然后S串是必须按照这个顺序去看的音乐会。

但是然后T串是。音乐会的时间安排。

问有多少种方案满足这个自己计划。


【题解】

然后定义dp[i][j],对应的是,已经完成第i~k及以后的计划,在第j天的这一天 方案数

可能比较绕。

从后往前考虑,

1、预处理出最后计划最后一场的位置的方案数为1。

2、然后从后往前进行递推。

 #include<bits/stdc++.h>
using namespace std;
const int N = 1e5+;
const int M = 3e2+;
const int mod = 1e9+;
typedef long long ll;
int f[N][M];
int S[N],T[N];
int n,k;
int w[];
char str[N];
int main()
{
scanf("%d%d",&k,&n);
for(int i=;i<;i++) scanf("%d",&w[i]); scanf("%s",str+);
for(int i=;str[i];i++) S[i] = str[i] - 'A'; scanf("%s",str+);
for(int i=;str[i];i++) T[i] = str[i] - 'A'; //初始化
for(int i=n;i>=;i--){
f[i][k] = f[i+][k] ;
if( T[i] == S[k] )
f[i][k] = f[i][k] + ;
} for(int i=n;i>=;i--){
for(int j=k-;j>=;j--){
f[i][j] = f[i+][j];
if( T[i] == S[j] && i+w[T[i]]+ <= n ){
f[i][j] = (int)((ll)f[i][j] + (ll)f[i+w[T[i]]+][j+] )% mod ;
}
}
} printf("%d\n",f[][]);
return ;
}

【动态规划】Concerts的更多相关文章

  1. 增强学习(三)----- MDP的动态规划解法

    上一篇我们已经说到了,增强学习的目的就是求解马尔可夫决策过程(MDP)的最优策略,使其在任意初始状态下,都能获得最大的Vπ值.(本文不考虑非马尔可夫环境和不完全可观测马尔可夫决策过程(POMDP)中的 ...

  2. 简单动态规划-LeetCode198

    题目:House Robber You are a professional robber planning to rob houses along a street. Each house has ...

  3. 动态规划 Dynamic Programming

    March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...

  4. 动态规划之最长公共子序列(LCS)

    转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ...

  5. C#动态规划查找两个字符串最大子串

     //动态规划查找两个字符串最大子串         public static string lcs(string word1, string word2)         {            ...

  6. C#递归、动态规划计算斐波那契数列

    //递归         public static long recurFib(int num)         {             if (num < 2)              ...

  7. 动态规划求最长公共子序列(Longest Common Subsequence, LCS)

    1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...

  8. 【BZOJ1700】[Usaco2007 Jan]Problem Solving 解题 动态规划

    [BZOJ1700][Usaco2007 Jan]Problem Solving 解题 Description 过去的日子里,农夫John的牛没有任何题目. 可是现在他们有题目,有很多的题目. 精确地 ...

  9. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

随机推荐

  1. Freestream边界条件【翻译】

    翻译自:CFD-online 帖子地址:http://www.cfd-online.com/Forums/openfoam-solving/93093-freestream-boundary-cond ...

  2. Java 面向对象(五)

    包装类 什么是包装类 在面向对象当中"一切皆对象".基本数据类型变量不是对象,比如 int a = 10; 当中就没有对象,所以就很矛盾.此时我们就可以对基本数据类型进行包装,把基 ...

  3. uploadify HTTP 302 错误如何解决?

    TP框架uploadify HTTP 302 错误如何解决?   在核心类文件夹里下的Conf/convention.php中 将 VAR_SESSION_ID打开(建议在模块的conf文件中添加配置 ...

  4. PowerDesigner 使用小结

    这里总结一篇关于数据建模工具 PowerDesigner 的使用小技巧,下面列出的两个应用场景要在网上现找解决方案的话还真不一定好找,所以选择将这两个棘手的问题先记下来. 1. PDM 中表间关系出现 ...

  5. SpringBoot表单数据校验

    Springboot中使用了Hibernate-validate作为默认表单数据校验框架 在实体类上的具体字段添加注解 public class User { @NotBlank private St ...

  6. SurfaceView双缓冲技术引入

    package com.loaderman.customviewdemo; import android.content.Context; import android.graphics.Canvas ...

  7. 机器学习 - 算法 - PCA 主成分分析

    PCA 主成分分析 原理概述 用途 - 降维中最常用的手段 目标 - 提取最有价值的信息( 基于方差 ) 问题 - 降维后的数据的意义 ? 所需数学基础概念 向量的表示 基变换 协方差矩阵 协方差 优 ...

  8. It’s worth noting值得注意的是

    It’s worth noting that in JavaScript applications the Model is often connected via Ajax to a back-en ...

  9. spring cloud+.net core搭建微服务架构

    http://www.cnblogs.com/longxianghui/p/7800316.html

  10. VS2015编译GDAL库出现宏重复定义 snprintf: 宏重定义

    E:\OpenSourceGraph\gdal-1.10.0\gdal\port      cpl_config.h   20行 #define HAVE_VPRINTF 1#define HAVE_ ...