Submission

Status:

(PPPPPPPPPP)(PPPPP)(PPPPP)(PPPPPPPPPP)

Subtask/Task Score:

{20/20}{30/30}{30/30}{20/20}

Score: 100

User: tHeNyXs

Problemset: กองไฟ

Language: cpp

Time: 0.009 second

Submitted On: 2026-03-05 18:46:43

#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9+7;

long long dp[51][51][51][3][3];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    int A,B,C;
    cin >> A >> B >> C;

    long long ans = 0;

    for(int first=0; first<3; first++){

        if(first==0 && A==0) continue;
        if(first==1 && B==0) continue;
        if(first==2 && C==0) continue;

        memset(dp,0,sizeof(dp));

        int a=A,b=B,c=C;

        if(first==0) a--;
        if(first==1) b--;
        if(first==2) c--;

        dp[a][b][c][first][first]=1;

        for(int i=a;i>=0;i--){
        for(int j=b;j>=0;j--){
        for(int k=c;k>=0;k--){
        for(int last=0;last<3;last++){
        for(int f=0;f<3;f++){

            long long cur=dp[i][j][k][last][f];
            if(!cur) continue;

            if(i>0 && last!=0)
                dp[i-1][j][k][0][f]=(dp[i-1][j][k][0][f]+cur)%MOD;

            if(j>0 && last!=1)
                dp[i][j-1][k][1][f]=(dp[i][j-1][k][1][f]+cur)%MOD;

            if(k>0 && last!=2)
                dp[i][j][k-1][2][f]=(dp[i][j][k-1][2][f]+cur)%MOD;

        }}}}}

        for(int last=0;last<3;last++){
            if(last!=first)
                ans=(ans+dp[0][0][0][last][first])%MOD;
        }
    }

    cout<<ans<<"\n";
}