题意:
N个人站成一行,每个人都戴着一顶帽子,(红,蓝或者绿
N个数Ai表示在第i个人前面有Ai个人和它的帽子颜色相同,问总共有多少种方案
题解:
计数现在总共有多少个红,蓝,绿的帽子,再判断有多少种颜色的帽子个数是和输入的数相等的,表示当前有多少种方案,乘一下即可
AC代码:
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<ext/rope>
#define endl '\n'
#define int long long
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
const int MAXN = 1e5+5;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
int c[3],a[MAXN];
signed main(){
int n,id,res=1; cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++){
int cnt=0;
if(a[i]==c[0]) { ++cnt; id=0; }
if(a[i]==c[1]) { ++cnt; id=1; }
if(a[i]==c[2]) { ++cnt; id=2; }
if(!cnt) { puts("0");return 0; }
res = (res*cnt)%MOD;
++c[id];
}
cout<<res<<endl;
return 0;
}