标签:math using xpl out scan main %s name ...
题目大意
看样例,懂题意
分析
实际就是个区间dp,我开始居然不会...详见代码(代码用的记忆化搜索)
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define sp cout<<"---------------------------------------------------"<<endl
const int mod=1e9;
char s[2000];
int n,dp[1100][1100];
int go(int l,int r){
if(l==r)return dp[l][r]=1;
if(dp[l][r]!=-1)return dp[l][r];
int res=0;
for(int i=l+1;i<=r-1;i+=2)
if(s[i]==s[l+1]&&s[i+1]==s[l]){
res+=(long long)go(l+1,i)*go(i+1,r)%mod;
res%=mod;
}
return dp[l][r]=res;
}
int main(){
freopen("exploring.in","r",stdin);
freopen("exploring.out","w",stdout);
int m,i,j,k;
scanf("%s",s+1);
n=strlen(s+1);
memset(dp,-1,sizeof(dp));
cout<<go(1,n)<<endl;
return 0;
}
标签:math using xpl out scan main %s name ...
原文地址:https://www.cnblogs.com/yzxverygood/p/9329165.html