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. [APIO2017]商旅——分数优化+floyd+SPFA判负环+二分答案

    题目链接: [APIO2017]商旅 枚举任意两个点$(s,t)$,求出在$s$买入一个物品并在$t$卖出的最大收益. 新建一条从$s$到$t$的边,边权为最大收益,长度为原图从$s$到$t$的最短路 ...

  2. C#图片灰度处理(位深度24→位深度8)、C#图片二值化处理(位深度8→位深度1)

    C#图片灰度处理(位深度24→位深度8) #region 灰度处理 /// <summary> /// 将源图像灰度化,并转化为8位灰度图像. /// </summary> / ...

  3. 服务端 CORS 解决跨域

    当协议.域名.端口中任一个不同时产生跨域 CORS 跨域资源共享(Cross-origin resource sharing) 参考资料https://developer.mozilla.org/zh ...

  4. linux pthread_cond_signal

      pthread_cond_signal函数的作用是发送一个信号给另外一个正在处于阻塞等待状态的线程,使其脱离阻塞状态,继续执行.如果没有线程处在阻塞等待状态,pthread_cond_signal ...

  5. MAC将根目录文件夹的权限赋给用户

    https://my.oschina.net/liujiest/blog/762004 1.sudu -i进入root模式(需输入密码) 2.chown -R 用户名 /文件夹名 sudo -i Pa ...

  6. 几种常见空间滤波器MATLAB实现

    本文链接:https://blog.csdn.net/LYduring/article/details/80443573 一.目的实现算术均值滤波器.几何均值滤波器.中值滤波器.修正的阿尔法均值滤波器 ...

  7. android.mk-include

    -- include $(BUILD_STATIC_LIBRARY)表示编译成静态库 include $(BUILD_SHARED_LIBRARY)表示编译成动态库. include $(BUILD_ ...

  8. 【转】nodejs接收前端formData数据

    很多时候需要利用formdata数据格式进行前后端交互. 前端代码可以是如下所示: <!DOCTYPE html> <html lang="en"> < ...

  9. Linux下设置Tomcat开机自启动

    --未验证 第一步:在/etc/init.d下新建一个文件tomcat(需要root操作权限) vi /etc/init.d/tomcat 然后点击"i"写下如下代码,tomcat ...

  10. std::wstring std::string w2m m2w

    static std::wstring m2w(std::string ch, unsigned int CodePage = CP_ACP) { if (ch.empty())return L&qu ...