Submission
Status:
(PPPPPPPPPP)(PPPPP)(PPPPP)(PPPPPPPPPP)
Subtask/Task Score:
{20/20}{30/30}{30/30}{20/20}
Score: 100
User: SnowAveNode
Problemset: กองไฟ
Language: cpp
Time: 0.004 second
Submitted On: 2026-04-22 18:49:09
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int nx = 1e5 + 5, MOD = 1e9 + 7, inf = 2e9; const ll INF = 4e18;
ll dp[2][52][52][3][3];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n,na,nb,nc; cin>>n>>na>>nb>>nc;
if(na>n/2 || nb>n/2 || nc>n/2) return cout<<0,0;
dp[0][1][0][0][0] = 1;
dp[0][0][1][1][1] = 1;
dp[0][0][0][2][2] = 1;
for(int i=0; i<n-1; i++) {
int cur = i % 2, next = (i+1) % 2;
memset(dp[next], 0, sizeof(dp[next]));
for(int a=0; a<=na; a++) {
for(int b=0; b<=nb; b++) {
int c = i+1-a-b;
if(c<0 || c>nc) continue;
for(int prev=0; prev<3; prev++) {
for(int first=0; first<3; first++) {
ll val = dp[cur][a][b][prev][first];
if(val == 0) continue;
if(a<na && prev!=0) dp[next][a+1][b][0][first] = (dp[next][a+1][b][0][first] + val) % MOD;
if(b<nb && prev!=1) dp[next][a][b+1][1][first] = (dp[next][a][b+1][1][first] + val) % MOD;
if(c<nc && prev!=2) dp[next][a][b][2][first] = (dp[next][a][b][2][first] + val) % MOD;
}
}
}
}
}
ll ans=0;
for(int prev=0; prev<3; prev++) {
for(int first=0; first<3; first++) {
if(prev==first) continue;
int last=(n-1)%2;
ans = (ans + dp[last][na][nb][prev][first]) % MOD;
}
}
cout << ans % MOD << '\n';
return 0;
}