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 ...
随机推荐
- unix c 04
系统调用(System Call) 文件的操作函数(Unix/Liunx系统内部提供的函数) time 可以查看程序的运行时间,包括用户层时间和系统层的时间. 系统调用其实就是一系列的 ...
- How to run OFBiz as a Service on linux
Windows See this specific guide: How to Run OFBiz as Windows Service with Java Service Wrapper Linux ...
- 初探JS正则表达式
1.概述 正则表达式是一个描述字符模式的对象.Javascript的正则表达式语法的是Perl5的正则表达式的子集.JS正则表达式有两种使用方式,文本模式和RegExp对象模式,实例如下: v ...
- Windows Live Writer 代码插件改造
源码和插件都在后面,如果不想看我神神叨叨的可以直接到文章后面下载 一 .找插件 在使用Windows Live Writer 经常要用到插入代码的功能,根据博客园中教程,分别使用了: WindowsL ...
- C++11里面的Lambda表达式
Lambda Expressions in C++ C++中的Lambda表达式 In Visual C++, a lambda expression—referred to as a lambda— ...
- [Immutable.js] Working with Subsets of an Immutable.js Map()
Immutable.js offers methods to break immutable structures into subsets much like Array--for instance ...
- STL中map,set的基本用法示例
本文主要是使用了STL中德map和set两个容器,使用了它们本身的一些功能函数(包括迭代器),介绍了它们的基本使用方式,是一个使用熟悉的过程. map的基本使用: #include "std ...
- jquery 图片比例不变,全屏居中
<!DOCTYPE html> <html> <head> <meta charset="gb2312"> <title> ...
- 关于arm-linux-gcc的安装与配置
在嵌入式开发中我们经常会用到arm-linux-gcc来编译我们的应用程序.作为arm-linux-gcc的入门,我们先看看如何安装arm-linux-gcc. 安装arm-linux-gcc还是比较 ...
- UIProgressView 圆角
里面外面都变成圆角 不用图片 直接改变layer 重点是里面外面都是圆角哦 for (UIImageView * imageview in self.progress.subviews) { imag ...