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 ;
}

最新文章

  1. GO语言练习:第一个Go语言工程--排序
  2. 使用media Queries实现一个响应式的菜单
  3. Xcode全局断点
  4. CloudFoundry Service 使用
  5. 数据库下载word预览功能的研究
  6. 如何做实时监控?—— 参考 Spring Boot 实现
  7. EF 事物
  8. js定义类或对象
  9. express 安装和运行
  10. Oracle SQLULDR2 以及 SQLLDR 进行导入导出的功能说明
  11. CSS伪类的理解
  12. p201 谱集是闭集 有界集
  13. ViewpageMaiActity
  14. MySQL学习(十)
  15. java Calendar类得到每个月的周末是几号的工具方法
  16. hive安装教程本地模式
  17. 20145236《网络对抗》Exp1 逆向及Bof基础
  18. Chrome V8引擎的一点认识
  19. nginx+jwplayer配置flv/MP4点播系统, 视频拖动支持
  20. CSS选择器之伪类选择器(元素)

热门文章

  1. hdu6468(记忆化搜索)
  2. Lucene4.2源码解析之fdt和fdx文件的读写——fdx文件存储一个个的Block,每个Block管理着一批Chunk,通过docID读取到document需要完成Segment、Block、Chunk、document四级查询,引入了LZ4算法对fdt的chunk docs进行了实时压缩/解压
  3. Leetcode题目437:路径总和III(递归-简单)
  4. ubuntu dnsmasq
  5. Android 查看和修改网络mtu
  6. git submodule 如何push代码
  7. 完全基于卷积神经网络的seq2seq
  8. IIS URL Rewriting and ASP.NET Routing
  9. Flutter移动电商实战 --(39)路由_Fluro的路由配置和静态化
  10. 二维背包---P1509 找啊找啊找GF