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. [Shell]Redis未授权访问反弹shell

    原作者:Cream 文章出处: 贝塔安全实验室 0x01 Redis未授权访问反弹shell Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value ...

  2. 2018-2019-2 20165222《网络对抗技术》Exp9 Web安全基础

    1.实践过程记录 1.字符串型注入. 2.整数型注入 3.注入语句查看其他内容 4.xss是一种漏洞,这种漏洞允许用户输入脚本并且浏览器提交的时候不加编码.这种东西是最为流行并且有害的web应用的问题 ...

  3. javasript模块化

    模块概述 随着一个网站越来越大,html页面文件越来越多,由<script src='xxx.js'></script>引入的js文件越来越多,我们的单个js文件很大,上几万行 ...

  4. Python JSON 字符串 转 json 基本使用

    字符串 转  json import json jsonData = '{"a":1,"b":2,"c":3,"d":4 ...

  5. docker pull 失败: server misbehaving

    在docker pull 镜像时一直报错: Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp: lo ...

  6. Restful API 架构与设计参考原则

    1. 什么是RESTREST全称是Representational State Transfer,中文意思是表述(编者注:通常译为表征)性状态转移. 它首次出现在2000年Roy Fielding的博 ...

  7. AT1357 n^p mod m(洛谷)

    题意翻译 求 n^p mod m 的值 输入格式 一行,为整数 n,m,p(注意顺序) 输出格式 一行,为 n^p mod m 的值 数据说明 对于100%的数据 1≤n,m≤10^91≤n,m≤10 ...

  8. c++ 套接字 --->2002 java NIO --->netty

    c++ 套接字 --->2002 java NIO --->netty

  9. js Map对象的用法

    第一篇: Map: Map是一组键值对的结构,具有极快的查找速度. 举个例子,假设要根据同学的名字查找对应的成绩,如果用Array实现,需要两个Array: var names = ['Michael ...

  10. 论文翻译 DOTA:A Large-scale Dataset for Object Detection in Aerial Images

      简介:武大遥感国重实验室-夏桂松和华科电信学院-白翔等合作做的一个航拍图像数据集 摘要: 目标检测是计算机视觉领域一个重要且有挑战性的问题.虽然过去的十几年中目标检测在自然场景已经有了较重要的成就 ...