uva 10617 Again Palindromes(DP)
来源:互联网 发布:mastercamx9编程技巧 编辑:程序博客网 时间:2024/05/29 03:41
Problem I
Again Palindromes
Input: Standard Input
Output: Standard Output
Time Limit: 2 Seconds
A palindorme is a sequence of one or more characters that reads the same from the left as it does from the right. For example,Z, TOT and MADAM are palindromes, butADAM is not.
Given a sequence S of N capital latin letters. How many ways can one score out a few symbols (maybe 0) that the rest of sequence become a palidrome. Varints that are only different by an order of scoring out should be considered the same.
Input
The input file contains several test cases (less than 15). The first line contains an integerT that indicates how many test cases are to follow.
Each of the T lines contains a sequence S (1≤N≤60). So actually each of these lines is a test case.
Output
For each test case output in a single line an integer – the number of ways.
Sample Input Output for Sample Input
3
BAOBAB
AAAA
ABA
22
15
5
#include <iostream>#include <cstdio>#include <string>using namespace std;const int maxn = 100;long long dp[maxn][maxn];string str;void initial(){for(int i = 0;i < maxn;i++){for(int j = 0;j < maxn;j++){dp[i][j] = 0;}}str.clear();}void DP(int i , int j){if(i == j){dp[i][j] = 1;return;}if(i > j){return;}if(dp[i+1][j-1] == 0){DP(i+1 , j-1);}if(dp[i][j-1] == 0){DP(i , j-1);}if(dp[i+1][j] == 0){DP(i+1 , j);}dp[i][j] = dp[i+1][j] + dp[i][j-1] - dp[i+1][j-1];if(str[i] == str[j]){dp[i][j] += dp[i+1][j-1]+1;}}void computing(){cin >> str;int len = str.length();DP(0 , len-1);cout << dp[0][len-1] << endl;}int main(){int t;cin >> t;while(t--){initial();computing();}return 0;}
- uva 10617 Again Palindromes(DP)
- Again Palindromes - UVa 10617 dp
- UVA 10617 Again Palindromes (区间dp)
- Uva 10617 Again Palindromes
- Again Palindromes+uva+回文串dp
- UVa 10617 Again Palindromes / 记忆化搜索
- uva 10617 - Again Palindrome(dp)
- UVA 10617 Again Palindrome --dp
- UVa 10617 - Again Palindrome 字符串dp
- Uva 10617 Again Palindrome(区间dp)
- uva 10617 Again Palindrome (DP)
- UVa 10617 Again Palindrome(回文 区间dp)
- Again Palindromes
- Uva 10617 Again Palindrome (区间DP+回文串)
- UVa 10617 Again Palindrome(回文串区间DP)
- UVA 题目10617 - Again Palindrome(区间DP)
- uva 11584 - Partitioning by Palindromes (dp)
- uva 11584 - Partitioning by Palindromes(简单dp)
- 三十四 assert()函数用法总结
- Shell脚本例子
- win8 64位安装sql 2005无法启动sql serve
- 三十五 #include <file>和#include“file”有什么不同?
- 发掘Scons
- uva 10617 Again Palindromes(DP)
- 转:免费WIFI卡位战升温:互联网巨头新一轮圈地
- 关于MySQL的load data infile
- onpaste事件的浅谈
- 二叉查找树
- 拓胜第十九天
- Leetcode: Search a 2D Matrix
- 三十六 fflush(stdout);
- 插入排序