A and B and Interesting Substrings(dp)

用Python+Charles搞定小程序付费短剧下载(附完整代码与避坑点) 本文详细介绍了如何利用Python和Charles抓包工具实现小程序付费短剧的自动化下载。通过分析小程序视频接口、破解请求参数,并编写Python脚本,读者可以轻松获取并保存短剧内容。文章还提供了完整的代码示例和常见问题的解决方案,特别适合对视频采集和抓包技术感兴趣的开发者。 阅读详情

A and B are preparing themselves for programming contests.

After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.

A likes lowercase letters of the Latin alphabet. He has assigned to each letter a number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes).

B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).

Also, A and B have a string s. Now they are trying to find out how many substrings t of a string s are interesting to B (that is, t starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.

Naturally, A and B have quickly found the number of substrings t that are interesting to them. Can you do it?

Input
The first line contains 26 integers xa, xb, …, xz ( - 105 ≤ xi ≤ 105) — the value assigned to letters a, b, c, …, z respectively.

The second line contains string s of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.

Output
Print the answer to the problem.

Sample test(s)
input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
xabcab
output
2
input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
aaa
output
2
Note
In the first sample test strings satisfying the condition above are abca and bcab.

In the second sample test strings satisfying the condition above are two occurences of aa.

有两个傻逼,一个喜欢子串,一个喜欢开头结尾一样字符的串,他们对每个字母定义了一个数值。
现在问满足这两个傻逼的要求,并且除去头尾字母,中间子母和为0的串的个数。

实在是不会= =,看了题解,自己对字符串真是好无力……前缀和什么的太弱了
其实题目的要求可以转化
…..x….x
就是对于第二个x的前缀和sum,之前x的前缀和中有多少个等于sum。(这样两个x中和一定是0,注意,第一个前缀和指得是从开头到x前一个字母的和,后一个前缀和的意思是指连上x的和)。
这样想到的话,加一个map映射就可以搞定了。

具体看一下代码,拿纸画一画就出来了。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
ll a[30];
map<ll,ll>mp[30];
char s[100005];
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\巍巍\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\巍巍\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    for(ll i = 1;i <= 26;i++)
        scanf("%lld",&a[i]);
    scanf("%s",s);
    ll len = strlen(s);
    ll sum = 0,ans = 0;
    for(ll i = 0;i < len;i++)
    {
        if(mp[s[i] - 'a' + 1].count(sum))
            ans += mp[s[i] - 'a' + 1][sum];
        sum += a[s[i] - 'a' + 1];
        mp[s[i] - 'a' + 1][sum]++;
    }
    printf("%lld\n",ans);
    return 0;
}
GD32F303定时器配置:实现两路互补PWM输出与相位控制 本文详细解析了基于GD32F303定时器实现两路互补PWM输出与精确相位控制的方法。通过配置TIMER2的中间对齐模式,结合REMAP功能解决引脚复用问题,从硬件层面稳定生成相位差180度的互补PWM信号,适用于电机驱动、开关电源等对时序要求苛刻的应用场景。 阅读详情

相关推荐

【MIT-BEVFusion代码解读】第四篇:融合特征fuser和解码特征decoder

的大小,实际上源代码也是这么做的。最后将得到两个分支的特征进行。,第一个特征使用卷积降低通道数即可,第二个则需要反卷积来提升。所以backbone只有两个分支,都是5个卷积模块组成。的长和宽都减半至90,然后在经过5个相同的。将通道降至128,后面再接5个相同的。,将通道数128上至256,并且将。特征进行融合,这里使用的。部分由两部分组成,分别是。,这个分支首先经过第一个。,然后再卷积得到 =>提取特征,最后得到特征。得到了两个大小不同的。

非晚非晚的博客 2954

A and B and Interesting Substrings

传送门 题目: A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, ...

qq_40584551的博客 232

别再只盯着照片了!手把手教你用Python提取大疆照片里的GPS、姿态和RTK数据

本文详细介绍了如何使用Python提取大疆照片中的GPS、姿态和RTK数据,帮助用户解锁无人机拍摄照片中的隐藏元数据。通过实战代码示例,展示了如何解析EXIF格式的定位、姿态和RTK状态信息,并实现批量处理与数据分析,适用于测绘、农业巡检等专业领域。

weixin_30790841的博客 153

Codeforces 519D A and B and Interesting Substrings

D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing

wulianxuyang 481

envi反演水质参数_遥感水质反演之反演模型

水质反演的框架图此为反演模型的章节第一部分,统计学基础:概率论、矩阵和数理统计的知识统计学知识框架# 1 基本统计概念知识在于应用,而非记忆!我们都是在样本的层面去操作数据的,以达到对总体性质的估计和推断,拿到一组数据首先进行基本的统计描述,常用的有:样本均值: 样本方差(调整方差)不是除以n,而是n-1, 标准差为样本方差开方即可皮尔逊积矩相关系数(简称相关系数): 相关系数范围在[-1,...

weixin_35275922的博客 3228

Blender学习笔记——制作向量场

#下载Blender - UE4 - FGA Vector Field Editor插件的压缩包,Github上的下载地址如下:https://github.com/isathar/Blender_UE4_VectorFieldEditor #下载并解压后将FGA VectorFields文件夹复制到C:\Program Files\Blender Foundation\Blender 2.83\2.83\scripts\addons目录下,此步骤可根据blender安装的位置自行调整,只要放入addon

wychao2020的博客 1724

[Codeforces #294(Div 2)]简要题解

A. A and B and ChessA and B are preparing themselves for programming contests.To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose

某沙茶的OI代码库 1007

排除 AcroForm 中 JavaScript 脚本的 Bug

本文介绍了Acrobat JavaScript脚本故障排除的基本方法。首先应检查控制台窗口的错误报告,通过具体示例演示了5类常见错误:语法错误(如缺少大括号)、未终止字符串、未定义变量、运算符混淆及变量作用域问题,并逐步给出修复方案。文章还提供了调试流程UML图和实用经验总结,强调关注细节(如分隔符匹配)、正确使用运算符和变量作用域等要点。最后建议采用系统化调试方法,包括关闭/重新打开表单等完整性测试。

小猫三两只。 1501

hash(Codeforces Round #294 (Div. 2)D. A and B and Interesting Substrings)

D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing themselve

龙崎的专栏 599

058、时域降噪(Temporal Denoise):运动补偿与递归滤波在视频降噪中的应用

本文深入探讨了时域降噪(Temporal Denoise)技术在视频处理中的应用。作者通过车载环视项目案例,揭示了空域降噪的局限性,提出利用帧间信息进行降噪的核心思路。文章详细解析了递归滤波和运动补偿两大关键技术,指出递归滤波简单但易产生拖影,而运动补偿通过计算运动矢量解决此问题。作者还分享了多帧降噪方案的优势与算力挑战,并总结了噪声模型匹配、运动矢量一致性等实战调优经验。最后强调时域降噪需要与空域降噪平衡,指出调试工具的重要性,提出"在保证运动区域无鬼影的前提下追求信噪比"的实践原则,体现了算法复杂度与效

zzfmlxs的博客 92

儿童启蒙教育APP

pinyinList.add(createPinyin("a", "啊,像阿姨的阿", R.raw.pinyin_a));pinyinList.add(createPinyin("i", "衣,像衣服的衣", R.raw.pinyin_i));pinyinList.add(createPinyin("u", "乌,像乌鸦的乌", R.raw.pinyin_u));pinyinList.add(createPinyin("ü", "鱼,像小鱼的鱼", R.raw.pinyin_v));-- 固定竖屏 -->

寒寒豆豆软件公司的博客 166

CF - 519D. A and B and Interesting Substrings - 前缀和思维+map

1.题目描述: D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B

终有绿洲摇曳在沙漠 860

Luma AI技术浅析(一)

是一款基于人工智能的3D内容生成平台,旨在通过深度学习技术实现高效、高质量的3D场景、物体和动画的生成。Luma AI 主要利用了等技术,以实现从图像、视频到3D模型的转换和生成。

m0_75253143的博客 1727

A and B and Interesting Substrings - CodeForces 519 D dp

A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing th

提比的强行AC 699

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

codeforces 519D D. A and B and Interesting Substrings(hash+dp)

题目链接:codeforces 519D题目大意:给出一个字符串,给出每个字母的权值,求字符串的子串中首尾相等,除去首尾字母的权值和为0的数量。题目分析:从前到后扫描字符串,计算前缀和,每次将前缀和Hash,然后每次查询与当前位字母相同的前缀和与当前前缀和相等的前缀的数量,间接地计算出字符串的数量。AC代码:#include <iostream> #include <cstring> #includ

llin-黎辰 820

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings [dp 前缀和 ]

传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing th...

weixin_33716557的博客 120

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

前缀和STL CF D A and B and Interesting Substrings

 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing themselves for programming contests. After

CQU_HYX的专栏 734

CF(#294 div2):D. A and B and Interesting Substrings

题目链接:http://codeforces.com/contest/519/problem/D  对于此题,刚开始我想到的是先把每个位置的和求出来,用sum[i]保存,然后把每种字母所在的位置求出来,用vector[i]来保存。这样一来我们就可以枚举每种字母,在枚举这种字母的位置,求出满足和为零的区间就可以了。可没想到的是这样的时间达到了O(n^2),行不通! 看了别人的代码,恍然大悟:因为

catch_catch的专栏 513

【codeforces】Round #294 (Div. 2) D. A and B and Interesting Substrings

D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing

Lost in your eyes 520

CodeForces - 519D A and B and Interesting Substrings (前缀和)

题意:         每个字母都有一个值,给你字符串s,求有多少个子串满足:         1.头尾字符相同         2.除了头尾字符,中间字符值的和为0 思路:         一开始想复杂了,又是区间查询,又是尺取法的,发现不行还得DP。其实维护每个字母的前缀和就行。 代码: #include using namespace std; const int M

DT2131 467

FZU 2218 Simple String Problem (状压DP解决集合不相同元素问题)

Recently, you have found your interest in string theory. Here is an interesting question about strings. You are given a string S of length n consisting of the first k lowercase letters. You are requ

MR CODER 250

(体会不同的编程思想的效率差异)A and B and Compilation Errors (看完题先思考如何解决更好)

A and B are preparing themselves for programming contests. B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code. Initially, the compiler

Markfound's blog 386

coderforce 519D A and B and Interesting Substrings

题目大意:给26个字母赋值,然后输入一个字符串,求首位和末位字符相同且首位和末位之间(不含端点)值的和为0的子串的个数 题目分析:预处理出前缀和,可以发现要满足中间和为0,只需要找前缀和相同的两个字符即可,然后用map离散一下数据,map[字符][对应的前缀和],每次sum加上对应的map值,相当于动态规划的过程#include #include #include #include using

小马的博客 349

CodeForces 519D A and B and Interesting Substrings

题意:给你每个字符的权值,然后给你一个字符串,找出其中满足首尾字符相同,中间一段的字符之和为0的子串个数。 分析:看到题目中要求某一段字符之和为0,先求出1~n的连续和,用s[i]表示1~i的和是多少。从s[0]开始,在哈希表中查找是否有和他相同的值,若有则说明他们之间的这一段字符串之和为0,而且如果他们的首字母和尾字母相同,那么我们就找到了一种情况,并且把当前的s[i]插入到哈希表中,

mxc的专栏 536

D. A and B and Interesting Substrings(前缀和+思维)

题目大意: 先输入26个字符[‘a’,‘z’]的权值,然后给你一个字符串,问你满足以下条件的字串有多少个。 1:第一个和最后一个字符的子串相等。 2:在这个子串中除掉第一个和最后一个字符的权值,剩下的字符权值之和等于0。 思路:求一段区间和我们可以用前缀和O(1)解决,但是要在一个串中找所有首位字符相等的字串的时间复杂度是O(n^2),因为N=1e5,这个时间复杂度肯定超时,所有我们要从别的角度...

weixin_43736492的博客 320

CF 两题

D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing themsel...

weixin_30608131的博客 167
上一篇: Maximum Absurdity(dp)
下一篇: Caesar's Legions(记忆化搜索)
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值