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

工业级Modbus ASCII实时监控系统(WinForms完整实现) 本文介绍了一个基于WinForms的工业级Modbus ASCII实时监控系统实现方案。该系统采用经典工控界面布局,包含串口配置、数据采集控制和实时数据显示三大区域。核心功能包括:串口通信参数设置、Modbus从站地址配置、寄存器数据采集、实时数据表格展示和趋势图绘制。系统通过ModbusAsciiClient类实现通信核心,采用定时器轮询机制采集数据,支持最多100个数据点的历史趋势显示。界面设计注重用户体验,配置区位于左侧,主显示区在右侧,底部为状态和日志区,符合工业控制系统的操作习惯。代码示例展示了窗 阅读详情

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第一个,第二个数也好求,最后一个数贪心搞,结果贪心写错了(贪心是可以过的),贪心求第三个数就是每个部分都尽量最大,

求第一个数dp【i】划分前i-1个总共有多少种方法,

不是很难想的dp,当时刚开始理解错题意了,浪费了很长时间,并且也有点困。。。。总之还是菜

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
const long long int mo=1000000007;
long long dp[1005],dp1[1005];
int main()
{
	int len,n,minn,maxx,ans,i,j,num[30],flog;
	char ch[1005];
	scanf("%d",&n);
	getchar();
	scanf("%s",ch);
	for(i=0;i<26;i++)
	scanf("%d",&num[i]);
	int inf=0x3f3f3f3f;
	memset(dp1,inf,sizeof(dp1));
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	dp1[0]=0;
	maxx=1;
	for(i=0;i<n;i++)
	{
		minn=num[ch[i]-'a'];
		len=1;
		for(j=i;j<n;j++,len++)
		{
			minn=min(minn,num[ch[j]-'a']);

			if(minn>=len)
			{
				dp[j+1]+=dp[i];
				dp[j+1]%=mo;
			}
			else
			{
				break;
			}
			maxx=max(maxx,len);
			dp1[j+1]=min(dp1[j+1],dp1[i]+1);
		}	
	}
	printf("%lld\n%d\n%d\n",dp[n],maxx,dp1[n]);

	return 0;
}


Python DEAP 库深度解析:从基础架构到高级应用 DEAP 是一个基于 Python 的开源框架,专门用于实现和运行各种进化算法,旨在帮助用户轻松地构建和调整进化算法,用于解决各种优化和搜索问题。本节中,介绍了 DEAP 相较于其它进化计算框架的优势,以及 DEAP 中重要的工具 creator 和 Toolbox。 阅读详情

相关推荐

23数字图像置乱技术(matlab程序)

所谓“置乱”,就是将图像的信息次序打乱,a像素移动到b像素位置上,b像素移动到c像素位置上,……,使其变换成杂乱无章难以辨认的图片。数字图像置乱技术属于加密技术,是指发送发借助数学或者其他领域的技术,对一幅有意义的数字图像做变换,使之变成一幅杂乱无章的图像用于传输。在图像传输过程中,它通过对图像像素矩阵的重排,破坏了图像矩阵的相关性,使非法截获者无法从杂乱无章的图像中获得原图像信息,以此实现信息的加密。接收方经去乱解密可恢复原图像。

m0_57943157的博客 1212

codeforces 766C Mahmoud and a Message(基础dp)

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

Chunzhen的博客 1020

基于PaddleX的垃圾分类识别

基于PaddleX的智能垃圾分类识别项目,使用百度开源的PaddlePaddle深度学习框架,结合PaddleX开发套件,实现对垃圾分类的识别检测

Mefishes的博客 8130

Codeforces 766 C Mahmoud and a Message(DP)

原题链接Problem DescriptionMahmoud 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

ZhaoYi1222的博客 497

从零到一:3D-ResNet50在医学影像中的实战陷阱与避坑指南

本文深入探讨了3D-ResNet50在医学影像分类中的实战应用,重点解析了NIFTI数据预处理、小样本迁移学习陷阱及GPU显存优化等关键问题。通过分块加载、混合精度训练等技巧,有效解决了医学影像处理中的内存管理和性能挑战,为开发者提供了实用的避坑指南和优化策略。

weixin_29038345的博客 393

从CentOS迁移到openEuler 24.03 LTS:手把手教你部署Java+MySQL+Redis+Nginx全栈环境

本文详细指导如何从CentOS迁移到openEuler 24.03 LTS,并部署Java+MySQL+Redis+Nginx全栈环境。涵盖系统配置、软件安装、性能优化及环境验证,助力企业级用户高效完成服务器迁移与部署。

weixin_26938645的博客 394

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

MobaXterm-SSH远程连接Ubuntu

我们常常在公司的服务器上面的虚拟机进行交叉编译,所以才需要我们用远程终端工具MobaXterm去接入虚拟机。然后把我们在window用VScode编辑好的代码拖拽上传到服务器,等待服务器编译完把生成的可执行文件从服务器拖拽下来,烧录到板子运行。

weixin_50257954的博客 3494

CF 766C - Mahmoud and a Message (DP+字符串)

题目链接: http://codeforces.com/problemset/problem/766/C 题目描述: 有一个只含小写字母的字符串,输入一个26个整数,用来限制每个字母所在字符串的最大长度,在保证符合限制的前提下。 输出分割字符串的方案数。 输出所有方案中,最少的分割次数。 输出所有方案中,最大的子串长度。 结题过程: ...

weixin_30615767的博客 156

高级数据库--作业及答案

中科大金培权老师的高级数据库课程作业及答案

一杯水果茶!足矣~ 1669

QGis二次开发 —— 2、第一个程序 - 加载栅格tif与矢量shp文件(附源码)

QGis二次开发 —— 2、第一个程序 - 加载栅格tif与矢量shp文件(附源码)

1104

Codeforces 766 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 characters dis

Tsaryu的博客 500

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

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.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

地址: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

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

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

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

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

spark__s的博客 484

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】

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+贪心)

题目链接 思路:一开始读错题意了,以为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

题目链接:这里 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

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 题目连接: 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

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
上一篇: 背包模板(01,完全,多重背包的二进制优化和单调队列优化
下一篇: HDU - 1520 Anniversary party 树形dp
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值