首页 > 学院 > 开发设计 > 正文

fzu 花生序列

2019-11-08 20:25:38
字体:
来源:转载
供稿:网友

强大的dp

二维数组水数据水过///

花生的序列

 FAQ | About | Google Group | Discuss | Author 
#include<stdio.h>#define mod 1000000007#include<string.h>#include<algorithm>using namespace std;int dp[1111][1111];char str[6666];int main(){    int t;    scanf("%d",&t);    while(t--)    {        int n;        scanf("%d",&n);        scanf(" %s",str+1);        memset(dp,0,sizeof(dp));        for(int i=0; i<=n; i++)            for(int j=0; j<=n; j++)            {                if(i||j)                {                    if(str[i+j]=='W')                    {                        if(i%2==1)                            dp[i][j]+=dp[i-1][j]%mod;                        if(j%2==1)                            dp[i][j]+=dp[i][j-1]%mod;                    }                    else if(str[i+j]=='B')                    {                        if(i%2==0&&i)                            dp[i][j]+=dp[i-1][j]%mod;                        if(j%2==0&&j)                            dp[i][j]+=dp[i][j-1]%mod;                    }                }                else dp[i][j]=1;            }        PRintf("%d/n",dp[n][n]%mod);    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表