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. avalon.js中使用owl-carousel轮播图

      <?php if($banners){?> <div class="ms-controller" ms-controller="bannerShow ...

  2. TCP/IP 这猝不及防的爱情

    前言 前几天看了老刘的一篇文章,TCP/IP 大明邮差.正好最近也在读<计算机自顶向下>一书 心血来潮,想写一个女版的TCP/IP 正文 一天,我正在百花会上赏花,赏着赏着,就出现了一个令 ...

  3. JDBC的概述和简单使用

    1. 概念 JDBC是 Java DataBase Connectivity 的简写,翻译过来就是 Java 操作数据库. 目的是使用统一的Java代码操作所有关系型数据库. JDBC实际是定义了一套 ...

  4. bind--dns-docker---[nslookup/dig]

    [dig]  https://www.cnblogs.com/apexchu/p/6790241.html [dns resolution and revserse ]https://www.cnbl ...

  5. JDK安装及Java环境变量配置

    1.JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html. 2.点击A ...

  6. docker-compose 布署应用nginx中的create-react-app应用获取环境变量

    文章来源:https://www.freecodecamp.org/news/how-to-implement-runtime-environment-variables-with-create-re ...

  7. xgboost 源码学习

    官方代码结构解析,README.MD XGboost 回归时,损失函数式平方误差损失 分类时,是对数自燃损失: Coding Guide ====== This file is intended to ...

  8. SUBMIT标准程序取ALV数据

    示例1: 调用J3RFLVMOBVEDH ,取物料的期初/ 期末庫存数.金额 FORM frm_call_j3rflvmobvedh. DATA: lr_bukrs TYPE RANGE OF buk ...

  9. Golang 开发框架 gin 项目时笔记

    1.模板引入时报错: func main() { router := gin.Default() router.LoadHTMLGlob("templates/**/*") rou ...

  10. (二十)sql基础

    sql基础 --单表查询 select * from student; select * from score; --投影查询 select * from student; --条件查询 select ...