BZOJ 1079-着色方案(DP)

1079: [SCOI2008]着色方案

Time Limit: 10 Sec   Memory Limit: 162 MB
Submit: 2097   Solved: 1265
[ Submit][ Status][ Discuss]

Description

  有n个木块排成一行,从左到右依次编号为1~n。你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块。
所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n。相邻两个木块涂相同色显得很难看,所以你希望统计任意两
个相邻木块颜色不同的着色方案。

Input

  第一行为一个正整数k,第二行包含k个整数c1, c2, ... , ck。

Output

  输出一个整数,即方案总数模1,000,000,007的结果。

Sample Input

3
1 2 3

Sample Output

10

HINT

 100%的数据满足:1 <= k <= 15, 1 <= ci <= 5

Source


dp[a][b][c][d][e][last]: 表示能染1块的颜色还有a种,2块的颜色还有b种.........

且上次染得是能够染last次的颜色中的一种

状态转移很好列,注意每次染完次数为x的颜色种的一种时次数为x-1的颜色数会多一种,

这就不用多说了吧。。。


#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
typedef long long  ll;
#define inf 10000000
#define mod 1000000007 
#define  maxn  505
#define  eps 1e-10
ll dp[16][16][16][16][16][16],cnt[16];
ll dfs(ll a,ll b,ll c,ll d,ll e,ll last)
{
	ll ans=0;
	if(a+b+c+d+e==0)
		return dp[a][b][c][d][e][last]=1;
	if(dp[a][b][c][d][e][last])
		return dp[a][b][c][d][e][last];
	if(a>0)
		ans+=(a-(last==2))*dfs(a-1,b,c,d,e,1),ans%=mod;
	if(b>0)
		ans+=(b-(last==3))*dfs(a+1,b-1,c,d,e,2),ans%=mod;
	if(c>0)
		ans+=(c-(last==4))*dfs(a,b+1,c-1,d,e,3),ans%=mod;
	if(d>0)
		ans+=(d-(last==5))*dfs(a,b,c+1,d-1,e,4),ans%=mod;
	if(e>0)
		ans+=e*dfs(a,b,c,d+1,e-1,5),ans%=mod;
	return dp[a][b][c][d][e][last]=ans%mod;
}
int  main(void)
{
	int k,i,x;
	scanf("%d",&k);
	for(i=1;i<=k;i++)
	{
		scanf("%d",&x);
		cnt[x]++;
	}
	printf("%lld\n",dfs(cnt[1],cnt[2],cnt[3],cnt[4],cnt[5],0));
	return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值