【BZOJ1079】[SCOI2008]着色方案【计数DP】【奇怪的姿势】

【题目链接】

想了一天多,感觉似乎只能是5^15。看了一下题解,发现还能这么玩...

神奇的题。

【iwtwiioi的题解】

/* Footprints In The Blood Soaked Snow */
#include <cstdio>

using namespace std;

typedef unsigned long long ULL;

const int maxn = 16, maxm = 7;
const unsigned int p = 1000000007;

int n, dp[maxn][maxn][maxn][maxn][maxn][maxm];

inline int iread() {
	int f = 1, x = 0; char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	return f * x;
}

inline int dfs(int a, int b, int c, int d, int e, int last) {
	if(!(a | b | c | d | e)) return 1;
	if(dp[a][b][c][d][e][last]) return dp[a][b][c][d][e][last];

	int ans = 0;
	if(a) ans = (ans + (ULL)(a - (last == 2)) * dfs(a - 1, b, c, d, e, 1) % p) % p;
	if(b) ans = (ans + (ULL)(b - (last == 3)) * dfs(a + 1, b - 1, c, d, e, 2) % p) % p;
	if(c) ans = (ans + (ULL)(c - (last == 4)) * dfs(a, b + 1, c - 1, d, e, 3) % p) % p;
	if(d) ans = (ans + (ULL)(d - (last == 5)) * dfs(a, b, c + 1, d - 1, e, 4) % p) % p;
	if(e) ans = (ans + (ULL)(e - (last == 6)) * dfs(a, b, c, d + 1, e - 1, 5) % p) % p;
	return dp[a][b][c][d][e][last] = ans;
}

int cnt[maxn];

int main() {
	n = iread();
	for(int i = 1; i <= n; i++) cnt[iread()]++;
	printf("%d\n", dfs(cnt[1], cnt[2], cnt[3], cnt[4], cnt[5], 0));
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值