Submission
Status:
(PPPPPPPPPP)(-SSSS)(-SSSS)(SSSSSSSSSS)
Subtask/Task Score:
{20/20}{0/30}{0/30}{0/20}
Score: 20
User: sorrkub
Problemset: กองไฟ
Language: cpp
Time: 0.006 second
Submitted On: 2026-02-16 23:57:29
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef pair<long long ,long long> pll; typedef pair<long long, pair<long long , long long >> plpll;
const int inf = 1e9+7;
int dx[8] = {0,0,-1,1,-1,1,-1,1} , dy[8] = {1,-1,0,0,1,-1,1,-1};
#define F first
#define S second
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);
int mem[51][51][51][4][4];
int n;
int fun(int a,int b, int c , int last,int first){
if(mem[a][b][c][last][first] !=-1 ){
return mem[a][b][c][last][first];
}
if(a+b+c == 0){
return mem[a][b][c][last][first] = 1;
}
if(a+b+c == 1){
if(a == 1){
return mem[a][b][c][last][first] = (first != 1 && last !=1) ? 1 : 0;
}
if(b == 1){
return mem[a][b][c][last][first] = (first != 2 && last !=2) ? 1 : 0;
}
if(c == 1){
return mem[a][b][c][last][first] = (first != 3 && last !=3) ? 1 : 0;
}
}
if(first == -1){
int i,j,k;
if(a>0){
i = fun(a-1,b,c,1,1)%inf;
}
if(b>0){
j = fun(a,b-1,c,2,2)%inf;
}
if(c>0){
k = fun(a,b,c-1,3,3)%inf;
}
return mem[a][b][c][last][first] = (i+j+k )%inf;
}
if(last == 1){
int i=0,j=0;
if(b>0){
i = fun(a,b-1,c,2,first)%inf;
}
if(c>0){
j = fun(a,b,c-1,3,first)%inf;
}
return mem[a][b][c][last][first] = (i+j)%inf;
}
if(last == 2){
int i=0,j=0;
if(a>0){
i = fun(a-1,b,c,1,first)%inf;
}
if(c>0){
j = fun(a,b,c-1,3,first)%inf;
}
return mem[a][b][c][last][first] = (i+j)%inf;
}
if(last == 3){
int i=0,j=0;
if(b>0){
i = fun(a,b-1,c,2,first)%inf;
}
if(a>0){
j = fun(a-1,b,c,1,first)%inf;
}
return mem[a][b][c][last][first] = (i+j)%inf;
}
return 67;
}
void solve(){
int a,b,c;cin>>n>>a>>b>>c;
memset(mem,-1,sizeof(mem));
cout<<fun(a,b,c,0,-1)%inf;
}
signed main(){
FAST_IO
int q=1;
//cin>>q;
while(q--){
solve();
}
return 0;
}
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \| |// `.
/ \||| : |||// \
/ _||||| -:- |||||- \
| | \ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pass System Test!
*/