Coderforces 7D hash+dp
来源:互联网 发布:乐乎公寓电话 编辑:程序博客网 时间:2024/05/29 12:58
点击打开链接
题意:题意比较简单不说了
思路:用hash来判断一下到当前位置是不是回文串,利用hash来写真的是很方便,然后一个(看似)简单的DP就OK了
#include <map>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const ll INF=0x3f3f3f3f3f3f3f3fll;const int maxn=5000010;char str[maxn];ull Hash[maxn],base[maxn],p=133331,A[maxn],B[maxn];ll dp[maxn];int main(){ base[1]=1;for(int i=2;i<maxn;i++) base[i]=base[i-1]*p; while(scanf("%s",str+1)!=-1){ int len=strlen(str+1); A[0]=0; for(int i=1;i<=len;i++) A[i]=A[i-1]*p+str[i]-'a'+1; B[0]=0; for(int i=1;i<=len;i++) B[i]=B[i-1]+(str[i]-'a'+1)*base[i]; ll ans=0; for(int i=1;i<=len;i++){ if(A[i]==B[i]){ dp[i]=dp[i>>1]+1; ans+=dp[i]; } } printf("%I64d\n",ans); } return 0;}
0 0
- Coderforces 7D hash+dp
- coderforces 846D Monitor
- Codeforces 7D Palindrome Degree 字符串hash DP
- 【DP】coderforces 567F
- 文章标题 coderforces 148D : Bag of mice (概率DP)
- CoderForces #282 Dic2 D--Obsessive String
- codeforces 519D D. A and B and Interesting Substrings(hash+dp)
- codeforces 7D Palindrome Degree 字符串hash
- CodeForces 7D Palindrome Degree 字符串hash
- [数据结构-hash]CF 7D Palindrome Degree
- coderforces round 19D线段树+离散化处理
- coderforces 814 D. An overnight dance in discotheque(贪心)
- Codeforce 65D - Harry Potter and the Sorting Hat(DP+hash+set)
- Codeforces Round #267 (Div. 2)D(DFS+单词hash+简单DP)
- CF271 D 字符串hash
- zoj 2672 DP+hash
- uva 10029 HASH + DP
- uva10029(hash + DP)
- git客户端保存用户名密码
- hdu3530Subsequence【单调队列优化dp】2010多校联合
- HDU 4445 Crazy Tank
- Hadoop Shell命令
- nginx中configure脚本支持的常用选项,拍摄自《Nginx高性能Web服务器详解》
- Coderforces 7D hash+dp
- PART2
- STM32:DMA方式接收SPI总线数据,并按照协议进行处理
- UVA - 839 Not so Mobile
- 数据结构--图(js版)
- Hadoop学习笔记(9)-搭建Hbase伪分布式及简单操作
- Ubuntu14.04中eclipse下编写mapreduce例子程序WordCount
- leetcode 242. Valid Anagram
- leetcode---Single Number II---二进制