# Iowa_Battleship

## BZOJ1079或洛谷2476 [SCOI2008]着色方案

### 洛谷原题链接

#include<cstdio>
using namespace std;
typedef long long ll;
const int N = 16;
const int mod = 1e9 + 7;
ll f[N][N][N][N][N][6];
int co[6];
int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c<'0' || c>'9'; c = getchar())
p = (c == '-' || p) ? 1 : 0;
for (; c >= '0'&&c <= '9'; c = getchar())
x = x * 10 + (c - '0');
return p ? -x : x;
}
ll dp(int a, int b, int c, int d, int e, int la)
{
ll s = 0, &k = f[a][b][c][d][e][la];
if (k)
return k;
if (!(a | b | c | d | e))
return 1;
if (a)
s += 1LL * (a - (la == 2))*dp(a - 1, b, c, d, e, 1);
if (b)
s += 1LL * (b - (la == 3))*dp(a + 1, b - 1, c, d, e, 2);
if (c)
s += 1LL * (c - (la == 4))*dp(a, b + 1, c - 1, d, e, 3);
if (d)
s += 1LL * (d - (la == 5))*dp(a, b, c + 1, d - 1, e, 4);
if (e)
s += 1LL * e*dp(a, b, c, d + 1, e - 1, 5);
k = s % mod;
return k;
}
int main()
{
int i, n;
n = re();
for (i = 1; i <= n; i++)
co[re()]++;
printf("%lld", dp(co[1], co[2], co[3], co[4], co[5], 0));
return 0;
}


posted on 2018-08-23 20:53  Iowa_Battleship  阅读(63)  评论(0编辑  收藏

• 随笔 - 172
• 文章 - 0
• 评论 - 20
• 引用 - 0