UESTC_How many good substrings CDOJ 1026
Icerain
likes strings very much. Especially the strings only consist of 0
and 1
,she call them easy strings. One day, she is so boring that she want to find how many good substrings in an easy string?
A good substring is a substring which can be a palindrome string after you change any two characters' positions(you can do this operation any times).For example,100 is a good substring of 1001,beacuse you can change it to be 010,which is a palindrome string.
Input
The first line is the number of test cases. (no more than 100)
Each test case has one line containing one string only consist of 0
and 1
. The length of the string is no greater than 100000.
Output
For each test case, output one line contains the number of good substrings.
Sample input and output
Sample Input | Sample Output |
---|---|
2 |
2 |
解题报告
前缀dp...感谢卿神指导..
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + ;
int dp[];
char buffer[maxn]; int main(int argc,char *argv[])
{
int Case;
scanf("%d",&Case);
while(Case--)
{
scanf("%s",buffer);
int len = strlen(buffer);
long long ans = ;
memset(dp,,sizeof(dp));
for(int i = ; i <= len ; ++ i)
{
int flag = ;
if (buffer[i-] == '')
{
swap(dp[],dp[]);
swap(dp[],dp[]);
flag = ;
}
else
{
swap(dp[],dp[]);
swap(dp[],dp[]);
}
if (flag)
dp[] ++ ;
else
dp[] ++ ;
ans += (dp[] + dp[] + dp[]);
}
cout << ans << endl;
}
return ;
}
UESTC_How many good substrings CDOJ 1026的更多相关文章
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- Leetcode: Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- HDU 1026 Ignatius and the Princess I(带路径的BFS)
http://acm.hdu.edu.cn/showproblem.php?pid=1026 题意:给出一个迷宫,求出到终点的最短时间路径. 这道题目在迷宫上有怪物,不同HP的怪物会损耗不同的时间,这 ...
- CSU-1632 Repeated Substrings (后缀数组)
Description String analysis often arises in applications from biology and chemistry, such as the stu ...
- cdoj 1489 老司机采花
地址:http://acm.uestc.edu.cn/#/problem/show/1489 题目: 老司机采花 Time Limit: 3000/1000MS (Java/Others) M ...
- CF451D Count Good Substrings (DP)
Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...
- code vs 1026 逃跑的拉尔夫
1026 逃跑的拉尔夫 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 年轻的拉尔夫开玩笑地从一个小镇上偷走 ...
- LA4671 K-neighbor substrings(FFT + 字符串Hash)
题目 Source http://acm.hust.edu.cn/vjudge/problem/19225 Description The Hamming distance between two s ...
- 后缀数组---New Distinct Substrings
Description Given a string, we need to find the total number of its distinct substrings. Input T- nu ...
随机推荐
- SQL查询最近三个月的数据(查询最近几天,几年等等)
定义和用法 :: 天,这样就可以找到付款日期. 我们使用如下 ,OrderDate) AS OrderPayDate FROM Orders 结果: OrderId OrderPayD ...
- 文本去重之SimHash算法
文本去重之SimHash算法 - pathenon的个人页面 - 开源中国社区 文本去重之SimHash算法
- linux之getcwd函数解析
[lingyun@localhost getcwd]$ cat getcwd.c /********************************************************** ...
- XHTML使用规范
XHTML元素语法: 1.XHTML元素必须正确嵌套 2.XHTML元素必须始终闭合 3.XHTML元素必须小写 4.XHTML文档必须有一个更元素 XHTML属性语法规则: 1 ...
- mycat实例(2)
全局序列号 数据切分后,原有的关系数据库中的主键约束在分布式条件下将无法使用,因此需要引入外部机制保证数据唯一性标识,这种保证全局性的数据唯一标识的机制就是全局序列号(sequence). 1. 本地 ...
- 关于safari上的select宽高问题小技,自定义下拉框
之前一直用windows做开发,最近换了个mac,在几经折腾之下,安装完了各种开发工具,IDE等,然后欣然打开自己正在开发的网站.突然发现mac上所有的下拉框都变了,都是默认样式,无论padding, ...
- DM6437 dsp系列之启动过程全析(2)—AIS文件解析
本文均属自己阅读源码的点滴总结,转账请注明出处谢谢. 欢迎和大家交流.qq:1037701636 email: gzzaigcn2009@163.com,gzzaigcn2012@gmail.com ...
- java与.net比较学习系列(3) 基本数据类型和类型转换
在Java中,数据类型分为两类,一类是基本数据类型,另外一类是引用类型. 而在C#中,数据类型分为三类,分别是基元类型,值类型和引用类型.其中基元类型是.net framework框架中预定义的类型, ...
- [Regular Expressions] Find a String that Precedes Another String ?= , ?!
Let's image tow cases for the following string: var str = `foo foobar foobaz fooboo` First of all: w ...
- LR使用Java User协议环境报错Please add the <JDK>\bin to the path and try again
看标题报错信息就知道,这是java编译及运行环境配置问题,运行LR脚本时,LR代理找不到java的JDK环境,当然,可能有人会遇到说,我在cmd窗口javac 环境是没问题的呀,是的,这就要看你的jd ...