• BZOJ 1079 [SCOI2008]着色方案


    题解:记忆化搜索

    本质不同的颜色就6种,能图0,1,2,3,4,5块木块的颜色

    f[x][a][b][c][d][e]表示上一块图的是本质为x的颜色,本质为1,2,3,4,5的颜色分别剩余a,b,c,d,e种的方案数

    转移枚举这一块填什么就行了

    还是写错了一个地方没查出来QWQ

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    const int mm=1000000007;
    
    int n,m;
    int c[6];
    int ans;
    
    int f[6][16][16][16][16][16];//最后1块填的是剩余数为i中的颜色,剩余数为1,2,3,4,5的颜色为a,b,c,d,e种的方案数 
    
    
    int Dp(int x,int a,int b,int c,int d,int e){
    	if(f[x][a][b][c][d][e])return f[x][a][b][c][d][e];
    	
    	if(a){
    		Dp(0,a-1,b,c,d,e);
    		if(1==x){
    			f[x][a][b][c][d][e]=(f[x][a][b][c][d][e]+f[0][a-1][b][c][d][e]*1LL*(a-1))%mm;
    		}else{
    			f[x][a][b][c][d][e]=(f[x][a][b][c][d][e]+f[0][a-1][b][c][d][e]*1LL*a)%mm;
    		}
    	}
    	if(b){
    		Dp(1,a+1,b-1,c,d,e);
    		if(2==x){
    			f[x][a][b][c][d][e]=(f[x][a][b][c][d][e]+f[1][a+1][b-1][c][d][e]*1LL*(b-1))%mm;
    		}else{
    			f[x][a][b][c][d][e]=(f[x][a][b][c][d][e]+f[1][a+1][b-1][c][d][e]*1LL*b)%mm;
    		}
    	}
    	if(c){
    		Dp(2,a,b+1,c-1,d,e);
    		if(3==x){
    			f[x][a][b][c][d][e]=(f[x][a][b][c][d][e]+f[2][a][b+1][c-1][d][e]*1LL*(c-1))%mm;
    		}else{
    			f[x][a][b][c][d][e]=(f[x][a][b][c][d][e]+f[2][a][b+1][c-1][d][e]*1LL*c)%mm;
    		}
    	}
    	if(d){
    		Dp(3,a,b,c+1,d-1,e);
    		if(4==x){
    			f[x][a][b][c][d][e]=(f[x][a][b][c][d][e]+f[3][a][b][c+1][d-1][e]*1LL*(d-1))%mm;
    		}else{
    			f[x][a][b][c][d][e]=(f[x][a][b][c][d][e]+f[3][a][b][c+1][d-1][e]*1LL*d)%mm;
    		}
    	}
    	if(e){
    		Dp(4,a,b,c,d+1,e-1);
    		if(5==x){
    			f[x][a][b][c][d][e]=(f[x][a][b][c][d][e]+f[4][a][b][c][d+1][e-1]*1LL*(e-1))%mm;
    		}else{
    			f[x][a][b][c][d][e]=(f[x][a][b][c][d][e]+f[4][a][b][c][d+1][e-1]*1LL*e)%mm;
    		}
    	}
    //	printf("%d %d %d %d %d %d %d %d
    ",x,n-a-b-c-d-e,a,b,c,d,e,f[x][a][b][c][d][e]);
    	return f[x][a][b][c][d][e];
    }
    
    int main(){
    	scanf("%d",&m);
    	while(m--){
    		int x;
    		scanf("%d",&x);
    		c[x]++;
    		n+=x;
    	}
    	
    	f[0][0][0][0][0][0]=1;
    	if(c[1]!=0)ans=(ans+Dp(0,c[1]-1,c[2],c[3],c[4],c[5])*1LL*c[1])%mm;
    	if(c[2]!=0)ans=(ans+Dp(1,c[1]+1,c[2]-1,c[3],c[4],c[5])*1LL*c[2])%mm;
    	if(c[3]!=0)ans=(ans+Dp(2,c[1],c[2]+1,c[3]-1,c[4],c[5])*1LL*c[3])%mm;
    	if(c[4]!=0)ans=(ans+Dp(3,c[1],c[2],c[3]+1,c[4]-1,c[5])*1LL*c[4])%mm;
    	if(c[5]!=0)ans=(ans+Dp(4,c[1],c[2],c[3],c[4]+1,c[5]-1)*1LL*c[5])%mm;
    	
    	printf("%d
    ",ans);
    	return 0;
    }
    

      

    自己还是太辣鸡了
  • 相关阅读:
    同步和异步Http请求工具类通过get和post方式发送请求
    c# IPC实现本机进程之间的通信
    C# 建立window服务
    WPF 将控件绑定到变量
    WPF触发器的使用
    C# DataTable 和List之间相互转换的方法
    WPF自适应窗体实现小结
    WPF简单导航框架(Window与Page互相调用)
    JavaEE框架面试题
    快速排序
  • 原文地址:https://www.cnblogs.com/zzyer/p/8454398.html
Copyright © 2020-2023  润新知