Concerts (DP)

约翰计划参加由A到Z的几个乐队的音乐会,每个乐队的票价不同,且约翰会在观看完某个乐队后休息一定天数。输入包含演出日程、休息天数和约翰想要观看的乐队列表,程序计算出约翰按顺序观看所有音乐会的可能方式数量(模10^9+7)。

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 (n ≤ 104
), there is exactly one concert. He decides to
show up at exactly k concerts (k ≤ 103
), 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 109 + 7.
Input
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.
Output
The number of ways in which he can schedule his attendance (mod 109 + 7).
Sample input Sample output
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

题目给的数组大小有误,注意数组大小

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const int M = 1e9 + 7;
int k, n, t;
int c[26];
int s[100005][305];  //按照题目给的大小开数组,很可能会Runtime Error
char a[305];
char b[100005];

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(0);
    cin >> k >> n;
    for (int i = 0; i < 26; i++) cin >> c[i];
    cin >> (a + 1) >> (b + 1);
    for (int j = 1; j <= k; j++) {
        for (int i = 1; i <= n; i++) {
            if (b[i] == a[j]) {
                if (j == 1)
                    s[i][j] = (LL)(s[i - 1][j] + 1) % M;
                else {
                    t = c[a[j - 1] - 'A'] + 1;
                    if (i - t <= 0)
                        s[i][j] = s[i - 1][j];
                    else
                        s[i][j] = (LL)(s[i - 1][j] + s[i - t][j - 1]) % M;
                }
            } else
                s[i][j] = s[i - 1][j];
        }
    }
    cout << s[n][k];
}
已经博主授权,源码转载自 https://pan.quark.cn/s/a4b39357ea24 QueueForMcu 基于单片机实现的队列功能模块,主要用于8位、16位、32位非运行RTOS的单片机应用,兼容大多数单片机平台。 开源代码:https://.com/xiaoxinpro/QueueForMcu 一、特性 动态创建队列对象 动态设置队列数据缓冲区 静态指定队列元素数据长度 采用值传递的方式保存队列数据 二、快速使用 三、配置说明 目前QueueForMcu只有一个静态配置项,具体如下: 在文件 中有一个宏定义 用于指定队列元素的数据长度,默认是 ,可以根据需要更改为其他数据类型。 四、数据结构 队列的数据结构为 用于保存队列的状态,源码如下: 其中 为配置项中自定义的数据类型。 五、创建队列 1、创建队列缓存 由于我们采用值传递的方式保存队列数据,因此我们在创建队列前要手动创建一个队列缓存区,用于存放队列数据。 以上代码即创建一个大小为 的队列缓存区。 2、创建队列结构 接下来使用 创建队列结构,用于保存队列的状态: 3、初始化队列 准备好队列缓存和队列结构后调用 函数来创建队列,该函数原型如下: 参数说明: 参考代码: 六、压入队列 1、单数据压入 将数据压入队列尾部使用 函数,该函数原型如下: 参数说明: 返回值说明: 该函数会返回一个 枚举数据类型,返回值会根据队列状态返回以下几个值: 参考代码: 2、多数据压入 若需要将多个数据(数组)压入队列可以使用 函数,原理上循环调用 函数来实现的,函数原型如下: 参数说明: 当数组长度大于队列剩余长度时,数组多余的数据将被忽略。 返回值说明: 该函数将返回实际被压入到队列中的数据长度。 当队列中的剩余长度富余...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值