【SCOI2008】着色方案
题目:
http://oj.changjun.com.cn/problem/detail/pid/2027
考虑记忆化搜索。
因为每种颜色能涂的木块<=5,设f[a][b][c][d][e][last]代表当前还剩a个能涂1的木块......上一个涂的木块是剩last的木块
则f[a,b,c,d,e,last]=(a-(last==2))*f[a-1,b,c,d,e]+(b-(last==3))*f[a+1,b-1,c,d,e]+
(c-(last==4))*f[a,b+1,c-1,d,e]+...+( e(last==6))*f[a,b,c,d+1,e-1]。
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<ctime>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define mod 1000000007
using namespace std;
int g[],n=,k;
LL f[][][][][][];//第六维判重
bool bj[][][][][][];
LL dfs(int a,int b,int c,int d,int e,int Last)
{
if(a+b+c+d+e==) return ;
if(bj[a][b][c][d][e][Last]) return f[a][b][c][d][e][Last]%mod;
LL ans=;
if(a) ans+=(a-(Last==))*dfs(a-,b,c,d,e,),ans%=mod;//放a
if(b) ans+=(b-(Last==))*dfs(a+,b-,c,d,e,),ans%=mod;//放b
if(c) ans+=(c-(Last==))*dfs(a,b+,c-,d,e,),ans%=mod;//放c
if(d) ans+=(d-(Last==))*dfs(a,b,c+,d-,e,),ans%=mod;//放d
if(e) ans+=(e-(Last==))*dfs(a,b,c,d+,e-,),ans%=mod;//放e
f[a][b][c][d][e][Last]=ans%mod;
bj[a][b][c][d][e][Last]=;
return ans%mod;
}
int main()
{
freopen("!.in","r",stdin);
freopen("!.out","w",stdout);
scanf("%d",&k);
int op;
for(int i=;i<=k;i++)
scanf("%d",&op),g[op]++;//能涂op个的数量
dfs(g[],g[],g[],g[],g[],);
printf("%lld",f[g[]][g[]][g[]][g[]][g[]][]);
return ;
}
【SCOI2008】着色方案的更多相关文章
- BZOJ 1079: [SCOI2008]着色方案 记忆化搜索
1079: [SCOI2008]着色方案 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
- bzoj1079: [SCOI2008]着色方案
ci<=5直接想到的就是5维dp了...dp方程YY起来很好玩...写成记忆化搜索比较容易 #include<cstdio> #include<cstring> #inc ...
- bzoj 1079: [SCOI2008]着色方案 DP
1079: [SCOI2008]着色方案 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 803 Solved: 512[Submit][Status ...
- [SCOI2008]着色方案
1079: [SCOI2008]着色方案 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2228 Solved: 1353[Submit][Stat ...
- [SCOI2008] 着色方案[高维dp]
321. [SCOI2008] 着色方案 ★★★ 输入文件:color.in 输出文件:color.out 简单对比时间限制:1 s 内存限制:64 MB 题目背景: 有n个木块排成一 ...
- 【BZOJ 1079】[SCOI2008]着色方案
Description 有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块.所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n.相邻两个木 ...
- BZOJ 1079: [SCOI2008]着色方案(巧妙的dp)
BZOJ 1079: [SCOI2008]着色方案(巧妙的dp) 题意:有\(n\)个木块排成一行,从左到右依次编号为\(1\)~\(n\).你有\(k\)种颜色的油漆,其中第\(i\)种颜色的油漆足 ...
- 【状态表示】Bzoj1096 [SCOI2008] 着色方案
Description 有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块.所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n.相邻两个木 ...
- [luogu2476][bzoj1079][SCOI2008]着色方案【动态规划】
题目描述 有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块.所有油漆刚好足够涂满所有木块,即c1+c2+-+ck=n.相邻两个木块涂相同色显得很难 ...
- SCOI2008着色方案(记忆化搜索)
有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i 种颜色的油漆足够涂ci 个木块.所有油漆刚好足够涂满所有木块,即 c1+c2+...+ck=n.相邻两个木块涂相同色显得很难 ...
随机推荐
- ECMAScript 6 笔记(五)
Iterator和for...of循环 1. Iterator(遍历器)的概念 Iterator接口的目的,就是为所有数据结构,提供了一种统一的访问机制,即for...of循环 遍历器(Iterato ...
- 钉钉开发笔记(6)使用Google浏览器做真机页面调试
注: 参考文献:https://developers.google.com/web/ 部分字段为翻译文献,水平有限,如有错误敬请指正 步骤1: 从Windows,Mac或Linux计算机远程调试And ...
- java二维数组学习(转)
转自:http://blog.csdn.net/java1992/article/details/5808709,在这里谢过了 /* * java学习: * 二维数组的使用: */public cla ...
- A manager is becoming more and more popular in China
A manager is becoming more and more popular in China; many people want to possess a position like th ...
- linux下php调试工具xdebug安装配置
xdebug简介 Xdebug是php的一款调试工具,是基于zend的一个扩展,可以用来跟踪,调试和分析PHP程序的运行状况.如变量,函数调试,性能监测,代码覆盖率等 xdebug安装 1.下载xde ...
- Xamarin组件包 Xamarin.ToolKit第二波
Xamarin.ToolKit第二波 一 圆角按钮 xamarin.froms提供的标准button按钮设置了圆角和边框,都没有明显圆角样式,于是乎自己重写了渲染类.道理吧就是重写ButtonRend ...
- cin的返回值
例: int main() { int a,b; while(cin >> a >> b) cout << a+b << endl; } 首先,cin是 ...
- 201521123014 java第一周总结
201521123014 java第一周总结 1.本周学习总结 刚认识这一门新语言,我就充满了好奇心,想看看Java和学过C语言,C++有什么区别.在这一周的学习中,我认识到,对于初学者而言,Java ...
- 开启AngularJS 1.X的学习之路(1)
概念(1) AngularJS 应用 AngularJS 模块(Module) 定义了 AngularJS 应用. AngularJS 控制器(Controller) 用于控制 AngularJS 应 ...
- 【转】jqGrid学习之安装
jqGrid安装很简单,只需把相应的css.js文件加入到页面中即可. 按照官网文档: /myproject/css/ ui.jqgrid.css /u ...