結果

問題 No.599 回文かい
ユーザー NekosyndromeNekosyndrome
提出日時 2017-11-24 22:54:20
言語 C++11
(gcc 13.3.0)
結果
MLE  
実行時間 -
コード長 1,006 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 161,108 KB
実行使用メモリ 396,364 KB
最終ジャッジ日時 2024-11-27 07:45:51
合計ジャッジ時間 13,942 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 MLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 10005
#define MOD 1000000007
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n,dp[M][M];
char in[M];
bool pal[M][M];
int calc(int l,int r)
{
	if(l>r) return 1;
	if(dp[l][r]!=-1) return dp[l][r];
	int &res = dp[l][r];
	res = 1;

	string ll="", rr="";
	for(int i=l; i<=n/2; i++) {
		int j = r-(i-l);
		ll = ll + in[i];
		rr = in[j] + rr;
		if(ll==rr)
		{
			res += calc(i+1, j-1);
			if(res>=MOD) res-=MOD;
		}
	}
	return res;
}
int main()
{
	while(~scanf("%s",in+1))
	{
		n = strlen(in+1);
		REP(i,0,n)REP(j,0,n) dp[i][j] = -1;

		printf("%d\n", calc(1,n));
	}
	return 0;
}


0