zoukankan      html  css  js  c++  java
  • BZOJ1079: [SCOI2008]着色方案

    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

     
    这道题设计状态很巧妙。
    设f[a][b][c][d][e][l]表示够涂1次的有a种油漆,够涂2次的有b种油漆,够涂3次的有c种油漆,够涂4次的有d种油漆,够涂5次的有e种油漆,上一次用的是够涂l次的油漆。
    状态转移就简单了。
    #include<cstdio>
    #include<cctype>
    #include<queue>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    #define rep(i,s,t) for(int i=s;i<=t;i++)
    #define dwn(i,s,t) for(int i=s;i>=t;i--)
    #define ren for(int i=first[x];i;i=next[i])
    using namespace std;
    const int BufferSize=1<<16;
    char buffer[BufferSize],*head,*tail;
    inline char Getchar() {
        if(head==tail) {
            int l=fread(buffer,1,BufferSize,stdin);
            tail=(head=buffer)+l;
        }
        return *head++;
    }
    inline int read() {
        int x=0,f=1;char c=getchar();
        for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
        for(;isdigit(c);c=getchar()) x=x*10+c-'0';
        return x*f;
    }
    typedef long long ll;
    const int mod=1000000007;
    int f[16][16][16][16][16][6];
    int dp(int a,int b,int c,int d,int e,int l) {
        if(a+b+c+d+e==0) return 1;
        int& ans=f[a][b][c][d][e][l];
        if(ans>=0) return ans;ans=0;
        if(a) (ans+=(ll)(a-(l==2))*dp(a-1,b,c,d,e,1)%mod)%=mod;
        if(b) (ans+=(ll)(b-(l==3))*dp(a+1,b-1,c,d,e,2)%mod)%=mod;
        if(c) (ans+=(ll)(c-(l==4))*dp(a,b+1,c-1,d,e,3)%mod)%=mod;
        if(d) (ans+=(ll)(d-(l==5))*dp(a,b,c+1,d-1,e,4)%mod)%=mod;
        if(e) (ans+=(ll)e*dp(a,b,c,d+1,e-1,5)%mod)%=mod;
        return ans;
    }
    int n,t[6];
    int main() {
        memset(f,-1,sizeof(f));
        int n=read();rep(i,1,n) t[read()]++;
        printf("%d
    ",dp(t[1],t[2],t[3],t[4],t[5],0));
        return 0;
    }
    View Code
  • 相关阅读:
    函数响应式编程
    RxSwift
    Swift 5.1 新语法
    MVVM
    SwiftUI 九
    SwiftUI 八
    SwiftUI制作View可嵌套组件
    Swift 5.1 新语法
    MVVM
    Linux系统修改hostname,不用重启
  • 原文地址:https://www.cnblogs.com/wzj-is-a-juruo/p/5017572.html
Copyright © 2011-2022 走看看