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

    1079: [SCOI2008]着色方案

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 822  Solved: 525
    [Submit][Status]

    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

    【样例2】 Input 5 2 2 2 2 2 Output 39480 【样例3】 Input 10 1 1 2 2 3 3 4 4 5 5 Output 85937576 数据规模】 50%的数据满足:1 <= k <= 5, 1 <= ci <= 3 100%的数据满足:1 <= k <= 15, 1 <= ci <= 5

    Source

    题解:

    想了一上午无果。。。

    此题困难之处在于状态的表示如果用 15个1-5的数来表示必然会T。。。蒟蒻没有想到剩下数相同的涂料可以平等看待,只用算一次就行了。。。

    如果我打了暴力的话,也许能想到?

    代码:

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<iostream>
     7 #include<vector>
     8 #include<map>
     9 #include<set>
    10 #include<queue>
    11 #define inf 1<<30
    12 #define maxn 500+100
    13 #define maxm 500+100
    14 #define eps 1e-10
    15 #define ll long long
    16 #define pa pair<int,int>
    17 #define mod 1000000007
    18 using namespace std;
    19 inline int read()
    20 {
    21     int x=0,f=1;char ch=getchar();
    22     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    23     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    24     return x*f;
    25 }
    26 ll f[16][16][16][16][16][6];
    27 bool mark[16][16][16][16][16][6];
    28 int n,x,a[6];
    29 ll dp(int a,int b,int c,int d,int e,int k)
    30 {
    31    if(mark[a][b][c][d][e][k])return f[a][b][c][d][e][k];
    32    if(a+b+c+d+e==0)return 1;
    33    ll t=0;
    34    if(a)t+=(a-(k==2))*dp(a-1,b,c,d,e,1);
    35    if(b)t+=(b-(k==3))*dp(a+1,b-1,c,d,e,2);    
    36    if(c)t+=(c-(k==4))*dp(a,b+1,c-1,d,e,3);
    37    if(d)t+=(d-(k==5))*dp(a,b,c+1,d-1,e,4);
    38    if(e)t+=e*dp(a,b,c,d+1,e-1,5);
    39    mark[a][b][c][d][e][k]=1;
    40    return f[a][b][c][d][e][k]=(t%mod);
    41 }
    42 int main()
    43 {
    44     freopen("input.txt","r",stdin);
    45     freopen("output.txt","w",stdout);
    46     n=read();
    47     while(n--)x=read(),a[x]++;
    48     printf("%lld
    ",dp(a[1],a[2],a[3],a[4],a[5],0));
    49     return 0;
    50 }
    View Code
  • 相关阅读:
    wqy的ACM赛G朱柏庐
    可持久化数据结构
    LibreOJ#2362蚯蚓
    LibreOJ#2359天天爱跑步
    「Luogu2221」[HAOI2012]高速公路
    「Luogu4158」[SCOI2009]粉刷匠
    「Luogu4317」花神的数论题
    WC2019 游记
    最大权闭合子图模型
    「Luogu2762」太空飞行计划问题
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3930921.html
Copyright © 2011-2022 走看看