BZOJ1079

http://hzwer.com/1884.html

解释得很清楚

注意F数组的定义

这么多维的DP写记忆化搜索会更好写

<span style="font-size:14px;">#include <iostream>
#include <cstdio>

#define mod 1000000007LL
#define N 16

using namespace std;

typedef long long LL;

int x[10],n;
LL F[N][N][N][N][N][6];
bool vis[N][N][N][N][N][6];

LL DP(int a,int b,int c,int d,int e,int k) {
	if (a+b+c+d+e == 0) return 1LL;
	if (vis[a][b][c][d][e][k]) return F[a][b][c][d][e][k];
	
	LL tmp = 0LL;
	if (a > 0) 
		tmp += 1LL * (a - (k == 2)) * DP(a-1,b,c,d,e,1);
	if (b > 0)
		tmp += 1LL * (b - (k == 3)) * DP(a+1,b-1,c,d,e,2);
	if (c > 0)
		tmp += 1LL * (c - (k == 4)) * DP(a,b+1,c-1,d,e,3);
	if (d > 0)
		tmp += 1LL * (d - (k == 5)) * DP(a,b,c+1,d-1,e,4);
	if (e > 0)
		tmp += 1LL * e * DP(a,b,c,d+1,e-1,5);
	
	vis[a][b][c][d][e][k] = true;
	return (F[a][b][c][d][e][k] =  (tmp % mod));
	//return tmp % mod;
		
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		int t = 0; scanf("%d",&t);
		x[t]++;
	}
	
	#ifndef ONLINE_JUDGE
		printf("%I64d\n",DP(x[1],x[2],x[3],x[4],x[5],0));
	#else
		printf("%lld\n",DP(x[1],x[2],x[3],x[4],x[5],0));
	#endif
	return 0;
}</span>


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值