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 ...
随机推荐
- Spring使用小结2
之前做过不少spring想过知识点内容的摘录, Spring框架的特点.模块组成.优缺点 spring相关的bean管理想过知识点及依赖注入方式 今天说下近端时间中项目中遇到的相关印象比较深的知识点 ...
- wikioi1369 xth 砍树
题目描述 Description 在一个凉爽的夏夜,xth 和 rabbit 来到花园里砍树.为啥米要砍树呢?是这样滴, 小菜儿的儿子窄森要出生了.Xth这个做伯伯的自然要做点什么.于是他决定带着 r ...
- UVA 10594-Date Flow(无向图的最小费用网络流+题目给的数据有误)
题意:给一个有N个点的无向图,要求从1向N传送一定的数据,每条边的容量是一定的,如果能做到,输出最小的费用,否则输出Impossible. 解析:由于是无向图,所以每个有连接的两个点要建4条边,分别是 ...
- mysql 编码设置
(windows下) 打开C:\Program Files\MySQL\MySQL Server 5.0\my.ini (ubuntu下) 打开 /etc/mysql/my.cnf 在[client] ...
- 炉石传说__multiset
炉石传说 Problem Description GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说.但是传统的炉石传说对于刚入门的GG学长来说有点复杂,所以他决定自己开发一个简化版 ...
- Bootstrap在线编辑器简单分享
Bootstrap 已经使响应式网站开发变得简单很多. 但是如果你不必手动写全部代码,事情会如何呢? 如果你可以自由地选择你想要使用的Bootstrap 组件.并可以把它们拖拽到画布中,事情会如何呢? ...
- html进阶css(2)
选择器的类型 <!doctype html> <html> <head> <meta charset="utf-8"> <ti ...
- 将集合类转换成DataTable
/// <summary> /// 将集合类转换成DataTale /// </summary> /// <param name="list"> ...
- Volley的三种基本用法StringRequest的Get和post用法以及JsonObjectRequest
首先做出整个应用的全局请求队列 package com.qg.lizhanqi.myvolleydemo; import android.app.Application; import com.and ...
- Windows7 无法打开ASA SSL VPN和ASDM首页
原文地址:Windows7 无法打开ASA SSL VPN 首页和无法打开 ASDM GUI 页面作者:futhy windows 7 无法打开ASA SSL VPN 和AS ...