E - Exploring Pyramids Gym - 101334E 分治



题意:

给出一段序列,从一个点开始回到这个点,问这个序列是否符合这个轨迹

题解:

分治,看代码就可以懂了



#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

#define LL long long
#define mod 1000000000
LL dp[320][320];
char str[310];

LL deal(int left,int right)
{
    if(dp[left][right]!=-1)    return dp[left][right];
    if(right==left)            return 1;
    if(str[left]!=str[right])  return 0;

    dp[left][right]=0;
    for(int i=left+2;i<=right;i++){
        if(str[i]==str[right]&&str[i]==str[left])
            dp[left][right]=(dp[left][right]+deal(left+1,i-1)*deal(i,right))%mod;
    }
    return dp[left][right];
}

int main()
{
    //freopen("in.txt","r",stdin);
    freopen("exploring.in","r",stdin);
    freopen("exploring.out","w",stdout);
    while(scanf("%s",str)!=EOF)
    {
        int len=strlen(str)-1;
        memset(dp,-1,sizeof(dp));
        printf("%lld\n",deal(0,len));
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值