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 ...
随机推荐
- POJ_Fibonacci POJ_3070(矩阵快速幂入门题,附上自己写的矩阵模板)
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10521 Accepted: 7477 Descri ...
- 再造轮子之网易彩票-第一季(IOS 篇 by sixleaves)
前言 在网上看了别人做的模仿网易彩票的项目, 于是也跟着用自己的想法做了一篇.写这篇博客的目的, 在于UI综合的一次小练习, 同时总结和串联其各个控件之间的应用.封装思想等.考虑到有人上不了githu ...
- SPRING+JNDI+C3P0 in tomcat6
Tomcat 中Jndi是使用Tomcat自带的连接池,由于客户要求,抛弃Tomcat自带的连接池.使用c3p0 .经过几个小时调试,解决方案如下: 环境:Tomcat 6 下面来看Jndi 与 c3 ...
- PHP批量审核后台
/*批量审核方法*/ function setOn_all() { if($_POST) { $p=M('news'); $data=array(); $i=0; foreach ($_POST as ...
- BOOST::Signals2
/* Andy is going to hold a concert while the time is not decided. Eric is a fans of Andy who doesn't ...
- 连数据库是ODBC好还是OLEDB好
1.连数据库是ODBC好还是OLEDB好?2.是不是只有微软的数据库才可以用OLEDB?3.要切换这两种连接,是不是只需要修改连接字符串?谢谢大家了,小弟对这三个问题不解 分享到: 2009-03 ...
- UISwitch + UIimage - 初识IOS
这里解释一个小例子,希望对你有点帮助,利用UISwitch控制UIimage的动画效果 先定义一个数组,用来存放照片,现在定义数组有一个特别简单的方法: NSArray *image1 = @[]; ...
- 在本地调试微信项目(C#)
之前一人负责微信的项目,那时2014年LZ还没毕业..啥都不懂,为此特别感谢@SZW,没有你的框架,我可能都无从下手 当时做项目最麻烦的就是调试,因为很多页面都要使用 网页授权获取用户信息 在电脑上打 ...
- java学习——abstract 和 final
当多个类中出现相同功能,但是功能主题不同,这时可以进行向上抽取.这时只抽取功能定义,而不抽取功能主体. 抽象:看不懂.1, 抽象方法一定定义在抽象类中.2, 抽象方法和抽象类都必须被abstract关 ...
- 关于用Java写的贪吃蛇游戏的一些感想
学习Java有那么一个月了,兴趣还是挺高的.然而最近老师布置的一个迷宫问题,着实让我头疼了一两个礼拜,以至于身心疲惫,困扰不安.无奈,暂且先放下这个迷宫问题,写个简单点的贪吃蛇程序,以此来提高低落的情 ...