hdu4632 Palindrome subsequence ——区间动态规划

link:http://acm.hdu.edu.cn/showproblem.php?pid=4632

refer to:

o(╯□╰)o……明明百度找的题解,然后后来就找不到我看的那份了,这位哥们对不住了……

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
char a[];
int dp[][];
const int MOD = ;
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
ios::sync_with_stdio(false);
int t; cin>>t;
for (int k = ; k <= t; ++k)
{
cin>>a; int len = strlen(a);
memset(dp, , sizeof(dp));
for (int i = ; i < len; ++i) for (int j = ; j < len; ++j)
if (i==j) dp[i][j] = ;
for (int i = ; i < len; ++i)
{
for (int j = ; i+j < len; ++j)
{
if (a[i+j] == a[j])
{
dp[j][i+j] = dp[j][i+j-] + dp[j+][i+j] + ;
}
else
{
dp[j][i+j] = dp[j+][i+j] + dp[j][i+j-] - dp[j+][i+j-];
}
dp[j][i+j] = (dp[j][i+j] + MOD)%MOD;
}
}
cout<< "Case "<<k<< ": "<<dp[][len-]<<endl;
}
return ;
}
/*
模拟一下第二个样例 aaaaa 就懂了
*/

o(╯□╰)o
永远感觉规划是一个很神奇的东西,比如这道。想明白了就感觉很神奇~

上一篇:git 还原某个文件到特定版本


下一篇:iis到w3wp的数据流及工作原理