zoukankan      html  css  js  c++  java
  • 洛谷 2476 [SCOI2008]着色方案

    50%的数据满足:1 <= k <= 5, 1 <= ci <= 3

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

    【题解】

      本题中ci很小,因此可以直接5维保存可以涂i块的油漆有多少种颜色。然后利用乘法原理进行DP

      

     1 #include<cstdio>
     2 #include<algorithm>
     3 #define LL long long
     4 #define rg register
     5 #define N 16
     6 #define Mod (1000000007)
     7 using namespace std;
     8 LL f[N][N][N][N][N][6];
     9 bool v[N][N][N][N][N][6];
    10 int n,cnt[6];
    11 inline int read(){
    12     int k=0,f=1; char c=getchar();
    13     while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    14     while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
    15     return k*f;
    16 }
    17 LL dfs(int a,int b,int c,int d,int e,int last){
    18     if(v[a][b][c][d][e][last]) return f[a][b][c][d][e][last];
    19     if(a+b+c+d+e==0) return 1;
    20     LL tmp=0;
    21     if(a) tmp+=(a-(last==2))*dfs(a-1,b,c,d,e,1);
    22     if(b) tmp+=(b-(last==3))*dfs(a+1,b-1,c,d,e,2);
    23     if(c) tmp+=(c-(last==4))*dfs(a,b+1,c-1,d,e,3);
    24     if(d) tmp+=(d-(last==5))*dfs(a,b,c+1,d-1,e,4);
    25     if(e) tmp+=e*dfs(a,b,c,d+1,e-1,5);
    26     v[a][b][c][d][e][last]=1;
    27     return f[a][b][c][d][e][last]=(tmp%Mod);
    28 }
    29 int main(){
    30     n=read();
    31     for(rg int i=1;i<=n;i++){
    32         int x=read();
    33         cnt[x]++;
    34     }
    35     printf("%lld
    ",dfs(cnt[1],cnt[2],cnt[3],cnt[4],cnt[5],0));
    36     return 0;
    37 }
    View Code
  • 相关阅读:
    第一节 软件测试概述(2)
    第一节 软件测试概述(1)
    Sql语句,查询效率
    Js cdn 学习
    Java内部类详解
    UML用例图
    UML类图几种关系的总结
    JFinal框架_定时触发程序
    利用EXCEL函数LINEST进行统计学中的回归分析
    Windows 10 64 Bit 编译安装 PyLucene 8.3.0
  • 原文地址:https://www.cnblogs.com/DriverLao/p/8724370.html
Copyright © 2011-2022 走看看