zoukankan      html  css  js  c++  java
  • bzoj 1079 DP

      比较容易看出来是DP,但是如果我们记录每一种颜色还剩多少种的话,消耗的转移的时间复杂度5^15,但是我们考虑到每一种颜色,如果数量相同的话,其实是等效的,所以我们用w[a][b][c][d][e][last]记录还剩下1,2,3,4,5次使用次数的颜色的数量为a,b,c,d,e,上一次我们那的是使用次数剩余为last的颜色,那么这次在剩余last-1次的颜色中,我们只能少拿一次,因为不能拿相同的,这样转移就很容易的表示出来了。

      我把存状态的数组都开到20就在0mstle了,改到16就好了,求指导。。。

    /**************************************************************
        Problem: 1079
        User: BLADEVIL
        Language: C++
        Result: Accepted
        Time:80 ms
        Memory:131876 kb
    ****************************************************************/
     
    //By BLADEVIL
    #include <cstdio>
    #define LL long long
    #define d39 1000000007
     
    using namespace std;
     
    int n,x;
    int sum[20];
    LL w[16][16][16][16][16][16];
     
    LL calc(int a,int b,int c,int d,int e,int last) {
        if (a+b+c+d+e==0) return w[a][b][c][d][e][last]=1;  
        if (w[a][b][c][d][e][last]) return w[a][b][c][d][e][last];
        LL sum=0ll;
        if (a) (sum+=(a-(last==2))*calc(a-1,b,c,d,e,1))%=d39;
        if (b) (sum+=(b-(last==3))*calc(a+1,b-1,c,d,e,2))%=d39;
        if (c) (sum+=(c-(last==4))*calc(a,b+1,c-1,d,e,3))%=d39;
        if (d) (sum+=(d-(last==5))*calc(a,b,c+1,d-1,e,4))%=d39;
        if (e) (sum+=e*calc(a,b,c,d+1,e-1,5))%=d39;
        return w[a][b][c][d][e][last]=sum;
    }
     
    int main(){
        scanf("%d",&n);
        while (n--) scanf("%d",&x),sum[x]++;
        LL ans=calc(sum[1],sum[2],sum[3],sum[4],sum[5],0);
        printf("%lld
    ",ans);
        return 0;
    }       
  • 相关阅读:
    数据访问技术系列课程 笔记(2) ADO.NET 连接方式进行数据访问
    Modern C# 系列课程笔记 第11节 深入委托和事件
    idea 将项目托管到 Git 报错:Can't finish Gitee sharing process
    ADO.Net
    WebService
    2013年了
    201301杂谈
    流程图
    出错列表
    杂谈4 2012年8月15日开
  • 原文地址:https://www.cnblogs.com/BLADEVIL/p/3568174.html
Copyright © 2011-2022 走看看