qscqesze
Published on 2017-09-02 11:31 in 暂未分类 with qscqesze

# 1079: [SCOI2008]着色方案

Time Limit: 20 Sec

Memory Limit: 256 MB

## 题目连接

http://www.lydsy.com/JudgeOnline/problem.php?id=1079

## Description

Input

Output

Sample Input

3
1 2 3

Sample Output

10

## HINT

#include<iostream>
#include<stdio.h>
using namespace std;
int tmp;
int dp;
int vis;
#define mod 1000000007
long long dfs(int a,int b,int c,int d,int e,int n){
if(vis[a][b][c][d][e][n])
return dp[a][b][c][d][e][n];
if(a+b+c+d+e==0)
return dp[a][b][c][d][e][n]=1;
long long ans=0;
if(a)ans+=(a-(n==2))*dfs(a-1,b,c,d,e,1);
if(b)ans+=(b-(n==3))*dfs(a+1,b-1,c,d,e,2);
if(c)ans+=(c-(n==4))*dfs(a,b+1,c-1,d,e,3);
if(d)ans+=(d-(n==5))*dfs(a,b,c+1,d-1,e,4);
if(e)ans+=(e-(n==6))*dfs(a,b,c,d+1,e-1,5);
vis[a][b][c][d][e][n]=1;
ans%=mod;
return dp[a][b][c][d][e][n]=ans;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int x;scanf("%d",&x);
tmp[x]++;
}
printf("%d\n",dfs(tmp,tmp,tmp,tmp,tmp,0));
}

posted @ 2015-11-05 22:24  qscqesze  阅读(...)  评论(... 编辑 收藏