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).

样例输入

  1. 2 10
  2. 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
  3. AB
  4. ABBBBABBBB

样例输出

  1. 10

【题意】

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

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

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

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

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


【题解】

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

可能比较绕。

从后往前考虑,

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

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1e5+;
  4. const int M = 3e2+;
  5. const int mod = 1e9+;
  6. typedef long long ll;
  7. int f[N][M];
  8. int S[N],T[N];
  9. int n,k;
  10. int w[];
  11. char str[N];
  12. int main()
  13. {
  14. scanf("%d%d",&k,&n);
  15. for(int i=;i<;i++) scanf("%d",&w[i]);
  16.  
  17. scanf("%s",str+);
  18. for(int i=;str[i];i++) S[i] = str[i] - 'A';
  19.  
  20. scanf("%s",str+);
  21. for(int i=;str[i];i++) T[i] = str[i] - 'A';
  22.  
  23. //初始化
  24. for(int i=n;i>=;i--){
  25. f[i][k] = f[i+][k] ;
  26. if( T[i] == S[k] )
  27. f[i][k] = f[i][k] + ;
  28. }
  29.  
  30. for(int i=n;i>=;i--){
  31. for(int j=k-;j>=;j--){
  32. f[i][j] = f[i+][j];
  33. if( T[i] == S[j] && i+w[T[i]]+ <= n ){
  34. f[i][j] = (int)((ll)f[i][j] + (ll)f[i+w[T[i]]+][j+] )% mod ;
  35. }
  36. }
  37. }
  38.  
  39. printf("%d\n",f[][]);
  40. return ;
  41. }

【动态规划】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. vue从一个组件跳转到另一个组件页面router-link的试用

    需求从helloworld.vue页面跳到good.vue页面 1.helloworld.vue页面代码 <template> <div class="hello" ...

  2. 深入了解JVM虚拟机8:Java的编译期优化与运行期优化

    java编译期优化 java语言的编译期其实是一段不确定的操作过程,因为它可以分为三类编译过程:1.前端编译:把.java文件转变为.class文件2.后端编译:把字节码转变为机器码3.静态提前编译: ...

  3. 《Glibc内存管理》笔记DAY2

    目录 Ptmalloc内存管理设计 Main_arena 与 non_main_arena chunk 的组织 空闲 chunk 容器 sbrk 与 mmap 内存分配概述 内存回收概述 边界标记法 ...

  4. [Ubuntu] 移植Ubuntu16.04根文件系统到嵌入式平台

    CPU:RK3288 1.通过 ubuntu cdimage 下载 ubuntu16.04 内核,以下两种方式都可以 在 windows 系统网页中下载 http://cdimage.ubuntu.c ...

  5. Java 面向对象(四)

    代码块 什么是代码块 在类中或方法当中 使用 { } 括起来的一段代码,就称它是一个代码块. 在代码块当中定义的变量我们称是局部变量,在外面是没有办法使用的.这里定义的 a 就是一个局部变量. 代码块 ...

  6. mac下如何安装python3?

    1. 安装homebrew $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/insta ...

  7. HTML5 地理位置定位API(5)

    HTML5 Geolocation API (地理位置应用程序接口) 目前PC浏览器支持情况: Firefox 3.5+Chrome 5.0+Safari 5.0+Opera 10.60+Intern ...

  8. 005-多线程-集合-Map-ConcurrentSkipListMap

    一.概述 ConcurrentSkipListMap是线程安全的有序的哈希表,适用于高并发的场景. ConcurrentSkipListMap和TreeMap,它们虽然都是有序的哈希表.但是,第一,它 ...

  9. 清空表且id为0

    sql命令: 用于清空某表的数据 且让自增的id重新从0开始 truncate table

  10. Qt坐标系以及自定义可移动控件

    1.效果 黑色这个控件是自定义的,可以在界面拖动 2.新建控件的Qt类,父类是QWidget,带ui的,Control.h #ifndef CONTROL_H #define CONTROL_H #i ...