Codeforces Round #396 (Div. 2) C.Mahmoud and a Message

开关电源设计实战:如何用AP值快速选型磁芯(附计算公式推导) 本文为开关电源工程师提供了基于AP值的磁芯快速选型实战指南。文章深入解析了AP值作为磁芯‘功率吞吐量’指标的核心物理意义,并通过详细的公式推导和24W反激电源设计实例,手把手演示如何利用AP值计算公式,结合电流密度、窗口利用率等关键参数,从众多磁芯型号中高效筛选出合适型号,同时强调了选型后的关键校验步骤与常见误区。 阅读详情

C. Mahmoud and a Message
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alphabet to be written on it in a string of length more than ai. For example, if a1 = 2 he can't write character 'a' on this paper in a string of length 3 or more. String "aa" is allowed while string "aaa" is not.

Mahmoud decided to split the message into some non-empty substrings so that he can write every substring on an independent magical paper and fulfill the condition. The sum of their lengths should be n and they shouldn't overlap. For example, if a1 = 2 and he wants to send string "aaa", he can split it into "a" and "aa" and use 2 magical papers, or into "a", "a" and "a" and use 3 magical papers. He can't split it into "aa" and "aa" because the sum of their lengths is greater than n. He can split the message into single string if it fulfills the conditions.

A substring of string s is a string that consists of some consecutive characters from string s, strings "ab", "abc" and "b" are substrings of string "abc", while strings "acb" and "ac" are not. Any string is a substring of itself.

While Mahmoud was thinking of how to split the message, Ehab told him that there are many ways to split it. After that Mahmoud asked you three questions:

  • How many ways are there to split the string into substrings such that every substring fulfills the condition of the magical paper, the sum of their lengths is n and they don't overlap? Compute the answer modulo 109 + 7.
  • What is the maximum length of a substring that can appear in some valid splitting?
  • What is the minimum number of substrings the message can be spit in?

Two ways are considered different, if the sets of split positions differ. For example, splitting "aa|a" and "a|aa" are considered different splittings of message "aaa".

Input

The first line contains an integer n (1 ≤ n ≤ 103) denoting the length of the message.

The second line contains the message s of length n that consists of lowercase English letters.

The third line contains 26 integers a1, a2, ..., a26 (1 ≤ ax ≤ 103) — the maximum lengths of substring each letter can appear in.

Output

Print three lines.

In the first line print the number of ways to split the message into substrings and fulfill the conditions mentioned in the problem modulo109  +  7.

In the second line print the length of the longest substring over all the ways.

In the third line print the minimum number of substrings over all the ways.

Examples
input
3
aab
2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output
3
2
2
input
10
abcdeabcde
5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output
401
4
3
Note

In the first example the three ways to split the message are:

  • a|a|b
  • aa|b
  • a|ab

The longest substrings are "aa" and "ab" of length 2.

The minimum number of substrings is 2 in "a|ab" or "aa|b".

Notice that "aab" is not a possible splitting because the letter 'a' appears in a substring of length 3, while a1 = 2.


感觉是很一道很好的dp题目,题目要求就是对于一个字符串,对于该字符串中的某一个字符,如果这个串的长度比这个字符的限制大,那么这个字符是不能显示的。

dp[i]表示以第i个字符结尾的情况数(字符串从1开始计数),定义j=1~i,如果字符串str[i-j+1,i]满足限制条件,那么dp[i]=dp[i]+dp[i-j]。

对于要算的最大的串长度,其实就是满足条件下的j的最大值 。

对于要算的最小分成的串数,定义f[i]为以第i个字符结尾时的结果。答案就是f[n]。在上面的 i,j循环中,对于每个i,在满足判断条件的时候f[i]=min(f[[i],f[i-j]+1)。可能不太好理解,看代码即可。

#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int lim[30];
char str[1005];
const int mod=1e9+7;
long long dp[1005];
int jishu[1005];
int f[1005];
bool check(int lef,int ri)
{
	int len=ri-lef+1;
	int f=1;
	for(int i=lef;i<=ri;i++)
	{
		if(len>lim[str[i]-'a'])
		{
			f=0;
			break;	
		}
		
	}
	if(f==0)
	return 0;
	else
	return 1;	
} 
int main()
{
	int n;
	int _max,_min;
	while(~scanf("%d",&n))
	{
		cin>>str+1;
		for(int i=0;i<26;i++)
		{
			scanf("%d",&lim[i]);
		}
		_max=0;
		dp[0]=1;
		for(int i=1;i<=n;i++)
		{
			f[i]=1e9; 
			for(int j=1;j<=i;j++)
			{
				if(check(i-j+1,i))
				{
					dp[i]+=dp[i-j]%mod;
					_max=max(j,_max);
					f[i]=min(f[i-j]+1,f[i]);
				}
			}
		}
		printf("%lld\n%d\n%d\n",dp[n]%mod,_max,f[n]);
	}
} 



瑞芯微RK3588/RK3576平台采集BT1120(fpga)驱动调试记录 本文介绍了在RK3576/RK3588平台上采集FPGA传输的BT1120数据的方法。主要内容包括:1)硬件连接需确认管脚复用和图像格式(通常为uyvy_2x8);2)设备树配置要点,如I2C总线设置、BT1120模式指定等;3)驱动适配注意事项,包括时钟极性、分辨率格式等关键参数;4)测试方法,通过media-ctl和v4l2-ctl工具验证数据采集。文中特别指出RK3576和RK3588配置的通用性,并提供了常见问题的排查思路。 阅读详情

相关推荐

ICT模拟零件测试方法--电容测试

通常,小到 100 pF 的电容需要补偿,因为夹具和系统的电容(20 到 50 pF)相对于被测设备的值是显著的。软件在需要补偿的电容测试中加入 comp 选项,而在不需要补偿的电容测试中加入 nocomp 选项。在调试期间,通过向电容语句添加 pc 选项验证您的电容测试。在测试单独的电容时,从测量结果中减去学到的值,然后与测试限制进行比较以决定通过或失败。请注意,如果用于需要补偿的电容测试上的感应总线使用了单独的探针,测量将无效。在测试电容时,应注意两个方面:电容的电阻元件,以及夹具和系统本身的电容。

可可南木的博客 1234

Codeforces 766 C Mahmoud and a Message 详解(DP)

C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wrote a message s of lengt

K键盘里的青春K 836

Ubuntu操作系统等保测评指南

Ubuntu操作系统等保测评指南

qq_40181198的博客 7050

Mahmoud and a Message - c (dp)

C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wrote a message s of length n. He wants to send ...

提拉米苏的博客 896

【工具】GitHub学生认证+PyCharm配置Copilot全流程指南

本文提供了一份详细的GitHub学生认证及在PyCharm中配置Copilot的完整指南。通过完成A2F认证、准备有效材料并使用干净网络环境,学生可免费获取GitHub Copilot Pro订阅,极大提升编程学习与开发效率。

w7x8y9z的博客 1470

用LTspice仿真CMOS反相器功耗?这份避坑指南能省你3天调试时间

本文详细介绍了如何使用LTspice准确仿真CMOS反相器的功耗,包括动态功耗、短路功耗和静态功耗的测量技巧。通过工程实践指南,帮助电子工程师避开常见陷阱,优化仿真参数设置,提升仿真结果的可靠性,节省调试时间。

w7x8y9z的博客 194

C. Mahmoud and a Message

C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wrote a message s of lengt

樱花满地集于我心,楪舞纷飞祈愿相随 1113

Python 爬虫实战:深入同花顺,抓取股票行情数据,助力投资决策

通过本次 Python 爬虫实战,我们成功地从同花顺抓取了股票行情数据,并进行了存储、处理、分析和可视化展示。在这个过程中,我们不仅掌握了爬虫技术的基本应用,还学会了如何对动态加载的数据进行处理和分析。然而,本次爬虫任务也存在一些局限性,例如仅爬取了部分股票的数据,且未对股票的历史行情进行深入分析。在未来的工作中,我们可以进一步优化爬虫程序,爬取更多股票的数据,并深入分析股票的历史行情走势、技术指标等,为投资者提供更有价值的数据支持。

u014481728的博客 5349

Codeforces Round #396 (Div. 2) C:Mahmoud and a Message(dp)

C. Mahmoud and a Messagetime limit per test:2 secondsmemory limit per test:256 megabytesinput:standard inputoutput:standard outputMahmoud wrote a message s of length n. He wants to send it as a birthda

妍恐龙的博客....^~^眼熟我 698

使用Google Earth Engine(GEE)的Python API,您可以将经纬度坐标转换为Landsat影像的路径/行号

使用Google Earth Engine(GEE)的Python API,您可以将经纬度坐标转换为Landsat影像的路径/行号。在这个示例中,我们选择了一个位于加利福尼亚州旧金山市附近的点,其经度为-122.084,纬度为37.421998。首先,我们需要导入必要的库和模块。接下来,我们定义一个函数,该函数将接收经度和纬度作为输入,并返回对应的Landsat路径/行号。最后,我们提取路径和行号的值,并将它们作为结果返回。现在,我们可以使用这个函数来获取特定点的Landsat路径/行号。

VwajAlgorithm的博客 354

msf后渗透之获取登入password、远程控制、调用摄像头

在terminal输入load kili creds_all直接获取密码(不一定成功) 使用kiwi_cmd sekurlsa::logonpasswords获取密码

m0_61506558的博客 2966

766C Mahmoud and a Message[字符串][简单dp]

C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wrote a message s of lengt

Qer的博客 541

KVM — 与 QEMU 和 Libvirt 的关系

目录目录 前言 KVM QEMU KVM 与 QEMU qemu-kvm Libvirt Libvirt 在 OpenStack 中的应用前言如果是刚开始接触虚拟机技术的话, 对上述的概念肯定会有所混淆, 傻傻的分不清. 尤其在看虚拟化技术文档时导致理解能力下降, 所以在开始学习虚拟化技术之前对这些概念有一个整体的认识和清晰的理解, 就显得很有必要了.KVMKVM(Kernel-basedVirtu

烟云的计算 5743

Codeforces Round #396 (Div. 2)C. Mahmoud and a Message

C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wrote a message s of lengt

jerans的博客 579

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Codeforces Round #396 (Div. 2) C. Mahmoud and a Message

地址:http://codeforces.com/contest/766/problem/C 题目: C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

weixin_30446197的博客 98

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Codeforces Round #396 (Div. 2) C - Mahmoud and a Message【DP】

请点击我直往原题~  题意: 给一串字符串,再给每个小写字母能处在的子串最大长度(例如 len(a) == 3,那么包含字母a字符串最大长度为3),求三个问题: 1.拆分方案数 2.最长子串 3.原串至少分成几部分 题解: 1.用dp1[i](1~n) 来维护到达第i个字符的最大方案数,dp2[i] 来维护最小拆分数。 2.第一层循环:i从1走到n。    第二层循环:j从字符的前一个i-1走到0

zehong1995的博客 260

Codeforces Round #396 (Div. 2) C. Mahmoud and a Message DP

C. Mahmoud and a Messagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMahmoud wrote a message s of length n. He wants to send it as a birthday p...

Frost_Bite的博客 375

C.Mahmoud and a Message Codeforces Round #396 (Div. 2)(DP)

题意就不说了,我们设一个dp数组,dp[i]表示长度为i的前缀有多少种符合条件的分割方法,dp[0]设置为1。 那么dp[i]=dp[i-1]+dp[i-2]+...+dp[i-j],j是当前第i个字符和第i-j+1个字符之间所包含字符对应的限制数组(题目中的ai)的最小值。所以在计算的时候,要不断更新 j 的值保证符合条件。 O(n^2)的时间复杂度算出dp[n]就是最多方案数。最长子串在

emmmmmm 2321

Codeforces Round #396 (Div. 2) C. Mahmoud and a Message(DP+贪心)

题目链接 思路:一开始读错题意了,以为26个字符的限制是值它们的次数,其实那26个元素的数组的意思是字符i不能存在超过limit【i】的字符串里,这样的话我们定义dp【i】为前i个字符成功分割满足要求的方案数,往后往前遍历看看当前区间是否可以,如果【j,i】的字符满足要求,那么dp【i】+=dp【i-j】,最大字串长度只要取最大的j就好了,至于最少分割数的话可以再设一个数组f,f【i】表示前i...

qq_42479630的博客 446

Codeforces Round #396(Div. 2)C. Mahmoud and a Message【dp】

C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wrote a message s of length n. He

mengxiang000000 452

Codeforces Round #396 (Div. 2) C. Mahmoud and a Message 倒着DP

题目链接:这里 Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characte

I good vegetable a! 447

Codeforces Round #396 (Div. 2) C. Mahmoud and a Message dp

C. Mahmoud and a Message 题目连接: http://codeforces.com/contest/766/problem/C Description Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes str...

weixin_30698297的博客 118

ACM_Codeforces Round #396(Div.2)_C_Mahmoud and a Message

C. Mahmoud and a Message time limit per test:2 seconds memory limit per test :256 megabytes input:standard input output:standard output Mahmoud wrote a message s of length n. He wants to send ...

晨起尘又落 618

Codeforces Round #396 (Div. 2) C. Mahmoud and a Message(DP)

C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wrote a message s of lengt

CillyB的博客 426
上一篇: Lotus and Horticulture(贪心)
下一篇: hdu4135 Co-prime(分解质因数,容斥)
spark__s
博客等级 码龄10年 1粉丝 48原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值