UPC 5130

5130: Concerts

时间限制: 1 Sec   内存限制: 128 MB
提交: 57   解决: 11
[ 提交][ 状态][ 讨论版][命题人: admin]

题目描述

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 ≤ 105), 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 109 + 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 109 + 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


题目的意思是某人想按照输入长度为k的这个顺序看演唱会,输入长度为n的这个是所有的顺序,然后A-Z代表的是看演唱会之前需要在家至少待几天。

就可以考虑到dp[i][j]=dp[i+1][j]+dp[i+str1[i]-'A'+1][j+1]  

从后往前考虑   然后注意开内存  开的恰好 否则会爆内存

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int mod=1e9+7;
char str1[350];
char str2[100005];
int valu[30];
int dp[100005][305];	
int main()
{
	int n,k;
	scanf("%d%d",&k,&n);
	for(int i=0;i<26;i++)
		scanf("%d",&valu[i]); 
	scanf("%s",str1+1);//k  需要比较的串 
	scanf("%s",str2+1);//n   母串 
	for(int i=n;i>=1;i--)//枚举最大的那个串 
	{
		for(int j=k;j>=1;j--)//枚举比较的串 
		{
			dp[i][j]=dp[i+1][j];
			if(j==k && str1[j]==str2[i])//如果当前是最后一个 而且等于上边的那个 
				dp[i][j]=(dp[i][j]+1)%mod;	
			else if(i+valu[str2[i]-'A']+1<=n && str2[i]==str1[j])
				dp[i][j]=(dp[i][j]+dp[i+valu[str2[i]-'A']+1][j+1])%mod;
		}
	}
	printf("%d\n",dp[1][1]);
	return 0;
} 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值