hduoj1544(判断连续回文)
来源:互联网 发布:钢管租赁计算软件 编辑:程序博客网 时间:2024/04/30 03:46
Palindromes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1509 Accepted Submission(s): 712
Problem Description
A regular palindrome(回文) is a string of numbers or letters that is the same forward as backward. For example, the string “ABCDEDCBA” is a palindrome because it is the same when the string is read from left to right as when the string is read from right to left.
Now give you a string S, you should count how many palindromes in any consecutive substring of S.
Input
There are several test cases in the input. Each case contains a non-empty string which has no more than 5000 characters.
Proceed to the end of file.
Output
A single line with the number of palindrome substrings for each case.
Sample Input
aba
aa
Sample Output
4
3
题解:从某一个开始,然后分偶数和奇数向左向右扩展,遇到不相等就退出,用二维dp会超时。
#include<iostream>#include<cstdio>#include<cstring>using namespace std;char str[5005];bool dp[5005][5005];int main(){ int len,i,j,cnt,l,r; while(scanf("%s",str)!=EOF){ len=strlen(str); cnt=len; for(i = 0 ; i < len ; i++){ l=i-1; r=i+1; while(l>=0&&r<len&&str[l]==str[r]){ l--;r++; cnt++; } l=i;r=i+1; while(l>=0&&r<len&&str[l]==str[r]){ l--;r++; cnt++; } } printf("%d\n",cnt); //cout<<cnt<<endl; } return 0;}
- hduoj1544(判断连续回文)
- 判断回文
- 回文判断
- 判断回文
- 判断回文
- 回文判断
- 回文判断
- 判断回文!
- 判断回文
- 回文判断
- 判断回文
- 回文判断
- 回文判断
- 判断回文
- 回文判断
- 回文判断
- 判断回文
- 回文判断
- Android WebView常见问题及解决方案汇总
- POJ -- 1201--Intervals (差分约束系统)
- 华为2016实习生面试感想
- O2O 行业 IT 系统架构实践分享——预告
- IP、子网掩码、缺省网关/默认网关、DNS、服务器、端口的总结
- hduoj1544(判断连续回文)
- html5背景视频使用总结
- 事件选择WSAEventSelect
- 在Visual studio中使用跟踪断点
- asyncTask基础
- u-boot链接脚本分析
- 陆续更新自己在南阳OJ刷题过程,以及蓝桥杯的训练
- mysql行转列(根据列明转换,列不能过多)
- Myeclipse设置jar文件的源代码