题意:
对于26个字母 每个字母分别有一个权值
给出一个字符串,找出有多少个满足条件的子串,
条件:1、第一个字母和最后一个相同,2、除了第一个和最后一个字母外,其他的权和为0

思路:
预处理出sum[i]:s[0~i]的和
开26个map<LL, LL>numV 分别表示 每个字母前缀和 的个数
例如处理到第i个元素,且numV[s[i]-'a'][sum[i]-v[s[i] - 'a']] (值为2)
表示在处理到的元素之前 以s[i]结尾的前缀和为sum[i]-v[s[i]-'a']的个数有2个
所以答案就要加2(因为前面已经组成过这个值,又出现的原因就是他的值变为了0)

 const int maxv = ;
int v[maxv];
map<LL, LL> numV[maxv]; const int maxn = + ;
char s[maxn];
LL sum[maxn];
void init()
{
for (int i = ; i < ; i++)
{
scanf("%d", v + i);
}
scanf(" ");
gets(s);
} void solve()
{
int len = strlen(s);
sum[] = v[s[]-'a'];
for (int i = ; i < len; i++)
{
sum[i] = sum[i-] + v[s[i]-'a'];
} LL ans = ;
for (int i = ; i < len; i++)
{
ans += numV[s[i]-'a'][sum[i] - v[s[i] - 'a']];
numV[s[i]-'a'][sum[i]]++;
}
printf("%lld\n", ans);
} int main()
{
init();
solve();
return ;
}

Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings的更多相关文章

  1. 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 megaby ...

  2. 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 me ...

  3. Codeforces Round #294 (Div. 2)

    水 A. A and B and Chess /* 水题 */ #include <cstdio> #include <algorithm> #include <iost ...

  4. Codeforces Round #294 (Div. 2)C - A and B and Team Training 水题

    C. A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input ...

  5. Codeforces Round #294 (Div. 2)B - A and B and Compilation Errors 水题

    B. A and B and Compilation Errors time limit per test 2 seconds memory limit per test 256 megabytes ...

  6. Codeforces Round #294 (Div. 2)A - A and B and Chess 水题

    A. A and B and Chess time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #294 (Div. 2) A and B and Lecture Rooms(LCA 倍增)

    A and B and Lecture Rooms time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. hbase数据迁移-HDFS拷贝

    1.把数据表test从hbase下拷出 hdfs dfs -get /hbase/data/default/test /home/hadoop/hbase/test 2.文件放到新集群的系统上 scp ...

  2. javascript页面加载完执行事件

    <script type="text/javascript" language="JavaScript"> //: 判断网页是否加载完成 docum ...

  3. OGG for DB2 z/OS 12.2版本发布

    2016-04-15 Oracle发布了GoldenGate for DB2 z/OS  12.2.0.1.2.可以从OTN或eDelivery下载,该版本是ogg for DB2 z/OS的第一个1 ...

  4. 搭建java开发环境、使用eclipse编写第一个java程序

    搭建java开发环境.使用eclipse编写第一个java程序 一.Java 开发环境的搭建 1.首先安装java SDK(简称JDK). 点击可执行文件 jdk-6u24-windows-i586. ...

  5. SHUTDOWN_MSG: Shutting down NameNode at java.net.UnknownHostException: xxx

    刚配置hadoop2.2,格式化namenode时候报的这个错. 原因是hadoop在格式化HDFS的时候,通过hostname命令获取到的主机名在/etc/hosts文件中进行映射的时候,没有找到, ...

  6. 基于eclipse-java的平台上搭建安卓开发环境

    首先感谢好人的分享!http://www.mamicode.com/info-detail-516839.html 系统:windows 7 若想直接安装eclipse—android的,请启动如下传 ...

  7. RABBITMQ(小总结 持续更新...

    (一)理解消息通信 1.消息通信概念---消费者.生产者和代理 生产者(producer)创建消息,然后发送到代理服务器(RaabitMQ). 其中消息包括两部分内容:有效载荷(payload)和标签 ...

  8. mybatis配置文件查询参数的传递

    通常来说,参数传递可以使用#与$进行编写,但是使用#的效率更高,使用$方式,查看日志更方便些,尤其是当执行的sql语句非常麻烦的时候. 1) 接口 形式 以下方式 [传递参数是一个实体] public ...

  9. c++ 泛型编程及模板学习

    泛型编程,英文叫做Generic programming 可以理解为,具有通用意义的.普适性的,编程. 比如,你要实现一个函数去比较两个数值的大小,数值可能是int或者string.初次尝试,我们直观 ...

  10. Ubuntu 14.04 安装VMware 12

    /*********************************************************************** * Ubuntu 14.04 安装VMware 12 ...