bzoj1079: [SCOI2008]着色方案

最近手风顺的不行啊,题题都是1A(这就是你刷水题的理由!?%题解当然1A啦。

然后今天写的就是这道小刚讲过的题,当时嫌六维DP太狗就没写。。

做法就是第一维表示上一个位置涂了什么色,然后二~六表示上限。

记忆化搜索。等等这东西好像两年没用了。。。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int mod=1000000007;

int h[6];
LL f[6][16][16][16][16][16];
LL dp(int last,int a,int b,int c,int d,int e)
{
    if(a<0||b<0||c<0||d<0||e<0)return 0;
    if(a==0&&b==0&&c==0&&d==0&&e==0)return 1;
    if(f[last][a][b][c][d][e]!=0) return f[last][a][b][c][d][e];
    
    LL ret=0;
    ret=( ret+ ((a-( (last==2) ? 1:0 ))*dp(1,a-1,b,c,d,e)) )%mod;
    ret=( ret+ ((b-( (last==3) ? 1:0 ))*dp(2,a+1,b-1,c,d,e)) )%mod;
    ret=( ret+ ((c-( (last==4) ? 1:0 ))*dp(3,a,b+1,c-1,d,e)) )%mod;
    ret=( ret+ ((d-( (last==5) ? 1:0 ))*dp(4,a,b,c+1,d-1,e)) )%mod;
    ret=( ret+ (e*dp(5,a,b,c,d+1,e-1)) )%mod;
    f[last][a][b][c][d][e]=ret;
    return ret;
}
int main()
{
    int n,x;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&x), h[x]++;
    memset(f,0,sizeof(f));
    printf("%lld
",dp(0,h[1],h[2],h[3],h[4],h[5]));
    return 0;
} 
原文地址:https://www.cnblogs.com/AKCqhzdy/p/8425067.html