Submission
Status:
(PPPPPPPPPP)(PPPPP)(PPPPP)(PPPPPPPPPP)
Subtask/Task Score:
{20/20}{30/30}{30/30}{20/20}
Score: 100
User: colo39
Problemset: กองไฟ
Language: cpp
Time: 0.007 second
Submitted On: 2026-11-27 22:55:42
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
map<int,int> cntp;
int st;
int dp[55][55][55][5];
int sol(int a, int b , int c ,int last) {
if (a+b+c == 0) return last != st;
if (dp[a][b][c][last] != -1) return dp[a][b][c][last];
int &r = dp[a][b][c][last];
r = 0;
if (last != 1 && a != 0) r+=sol(a-1,b,c,1);
if (last != 2 && b != 0) r+=sol(a,b-1,c,2);
if (last != 3 && c != 0) r+=sol(a,b,c-1,3);
return r %= MOD;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,na,nb,nc;
cin >> n >> na >> nb >> nc;
cntp[1] = na;
cntp[2] = nb;
cntp[3] = nc;
int cnt = 0;
for (st = 1;st <= 3;st++) {
memset(dp,-1,sizeof(dp));
if (cntp[st] != 0 && st == 1) {
cnt += sol(na-1,nb,nc,st) % MOD;
}
if (cntp[st] != 0 && st == 2) {
cnt += sol(na,nb-1,nc,st) % MOD;
}
if (cntp[st] != 0 && st == 3) {
cnt += sol(na,nb,nc-1,st) % MOD;
}
}
cout << cnt % MOD;
return 0;
}