101334E Exploring Pyramids

Posted yzxverygood

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了101334E Exploring Pyramids相关的知识,希望对你有一定的参考价值。

传送门

题目大意

看样例,懂题意

分析

实际就是个区间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;
}

以上是关于101334E Exploring Pyramids的主要内容,如果未能解决你的问题,请参考以下文章

Gym 101334E dp

Exploring Python Code Objects

Exploring ARM64 runtime patching alternatives

Exploring ARM64 runtime patching alternatives

[Immutable.js] Exploring Sequences and Range() in Immutable.js

[ES7] Exploring ES2016 Decorators