日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

1276. Train

系統(tǒng) 2610 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為結(jié)尾的種類數(shù)量

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

然后根據(jù)結(jié)尾是A還是B 進(jìn)行向后更新數(shù)量

代碼:

      #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


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

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

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 靖安县| 响水县| 固原市| 通道| 永福县| 枣强县| 台江县| 阿克| 耿马| 黄冈市| 贺兰县| 柘城县| 常熟市| 永泰县| 闽侯县| 大港区| 湖南省| 彭阳县| 星座| 桃江县| 同心县| 图木舒克市| 武定县| 靖宇县| 长汀县| 同仁县| 万全县| 阿鲁科尔沁旗| 樟树市| 牙克石市| 常熟市| 突泉县| 乌海市| 阳曲县| 石楼县| 双流县| 亳州市| 湾仔区| 舟山市| 综艺| 凤阳县|