现在的位置: 首页 > 综合 > 正文

1079: [SCOI2008]着色方案

2018年01月13日 ⁄ 综合 ⁄ 共 787字 ⁄ 字号 评论关闭
#include<iostream>
#include<cstdio>
#define mod 1000000007
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int k,a[6];
long long f[16][16][16][16][16][6];
bool pd[16][16][16][16][16][6];
long long dp(int a,int b,int c,int d,int e,int k){
    long long t=0;
    if(pd[a][b][c][d][e][k])return f[a][b][c][d][e][k];
    if(a+b+c+d+e==0)return 1;
    if(a)t+=(a-(k==2))*dp(a-1,b,c,d,e,1);
    if(b)t+=(b-(k==3))*dp(a+1,b-1,c,d,e,2);
    if(c)t+=(c-(k==4))*dp(a,b+1,c-1,d,e,3);
    if(d)t+=(d-(k==5))*dp(a,b,c+1,d-1,e,4);
    if(e)t+=e*dp(a,b,c,d+1,e-1,5);
    pd[a][b][c][d][e][k]=1;
    return f[a][b][c][d][e][k]=t%mod;
}
int main(){
    k=read();
    for(int i=1;i<=k;i++){
        int x=read();
        a[x]++;
    }
    printf("%lld",dp(a[1],a[2],a[3],a[4],a[5],0));
    return 0;
}

抱歉!评论已关闭.