欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

1276. Train

系統 2578 0

http://acm.timus.ru/problem.aspx?space=1&num=1276

用 ans[numaa][numab][numba][numbb][0] 表示用 numaa個AA ?numab個AB? numba個BA ?numbb個BB?? 以 A為結尾的種類數量

用 ans[numaa][numab][numba][numbb][1] 表示用 numaa個AA? numab個AB? numba個BA ?numbb個BB?? 以 B為結尾的種類數量

然后根據結尾是A還是B 進行向后更新數量

代碼:

      #include<iostream>

#include<stdio.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<vector>

#include<set>

#include<map>

#include<string>

#include<queue>

#include<stack>

#include <iomanip>

using namespace std;

#define LL long long

const int INF=0x3f3f3f3f;

const int N=45;

LL ans[20005][2];

int aa,ab,ba,bb;

int F(int i,int j,int l,int r)

{

    int x=r;

    x+=(l*bb);

    x+=(j*ba*bb);

    x+=(i*ab*ba*bb);

    return x;

}

int main()

{

    //freopen("data.in","r",stdin);

    int n,k;

    while(cin>>n>>k)

    {

        ab=0;aa=0;ba=0;bb=0;

        string stmp;

        int locomotive;

        cin>>stmp;

        if(stmp=="AA") locomotive=0;

        if(stmp=="AB") locomotive=1;

        if(stmp=="BA") locomotive=2;

        if(stmp=="BB") locomotive=3;

        for(int i=1;i<=n;++i)

        {

            cin>>stmp;

            if(stmp=="AA") ++aa;

            if(stmp=="AB") ++ab;

            if(stmp=="BA") ++ba;

            if(stmp=="BB") ++bb;

        }

        ++aa;++ab;++ba;++bb;

        memset(ans,0,sizeof(ans));

        if(locomotive==0||locomotive==2)

        ans[0][0]=1;

        else

        ans[0][1]=1;

        LL sum=0;

        for(int i=0;i<aa;++i)

        for(int j=0;j<ab;++j)

        for(int l=0;l<ba;++l)

        for(int r=0;r<bb;++r)

        if(i+j+l+r<=k)

        {

            int x=F(i,j,l,r);

            if(i+j+l+r==k)

            {

                if(locomotive==0||locomotive==1)

                sum+=ans[x][0];

                else

                sum+=ans[x][1];

            }

            if(ans[x][0]!=0)

            {

                if(i+1<aa)

                ans[F(i+1,j,l,r)][0]+=ans[x][0];

                if(j+1<ab)

                ans[F(i,j+1,l,r)][1]+=ans[x][0];

            }

            if(ans[x][1]!=0)

            {

                if(l+1<ba)

                ans[F(i,j,l+1,r)][0]+=ans[x][1];

                if(r+1<bb)

                ans[F(i,j,l,r+1)][1]+=ans[x][1];

            }

        }

        if(sum==0)

        cout<<"NO"<<endl;

        else

        {cout<<"YES"<<endl;cout<<sum<<endl;}

    }

    return 0;

}


    

1276. Train


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日本视频免费高清一本18 | 五月婷婷六月天 | 麻豆md国产在线观看 | 久草在在线| 成人午夜视频在线观看 | 日本在线高清视频 | 99久久99久久免费精品蜜桃 | 新视觉yy6080午夜毛片 | 这里只有精品99re | 亚洲一区二区三区四 | 上海一级毛片 | 99热综合在线 | 久久院线 | 国产精品视频久久 | 不卡久久 | 久久久久久免费播放一级毛片 | 狠狠撸电影院 | 亚洲黄区 | 日韩亚洲一区二区三区 | 一个色综合网站 | 一区二区三区在线 | 99精品国产一区二区青青牛奶 | 无码激情做A爰片毛片A片小说 | 美女爽到呻吟久久久久 | 五月激情六月 | 成人免费xxxxx在线观看 | 久久久国产99久久国产首页 | 亚洲国产天堂久久精品网 | 国产传媒在线视频 | 国产精品久久自在自2021 | 6全高清智能录播系统视频 精品九九 | 久久99国产精品久久99无号码 | 久久6699精品国产人妻 | 黄色在线观看 | 久久精彩| 欧美一区二区三区四区夜夜大片 | 婷婷在线免费视频 | 九七婷婷狠狠成人免费视频 | 久久精品小视频 | 999精品嫩草久久久久久99 | 成年视频在线观看免费 |