bzoj1079 [SCOI2008]着色方案
Description
有n个木块排成一行,从左到右依次编号为1~n。你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块。所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n。相邻两个木块涂相同色显得很难看,所以你希望统计任意两个相邻木块颜色不同的着色方案。
Input
第一行为一个正整数k,第二行包含k个整数c1, c2, ... , ck。
Output
输出一个整数,即方案总数模1,000,000,007的结果。
Sample Input
1 2 3
Sample Output
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
#define mod 1000000007
using namespace std;
inline LL read()
{LL x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
LL f[16][16][16][16][16][6];
bool mrk[16][16][16][16][16][6];
int rep[6];
int n;
inline LL cal(int a1,int a2,int a3,int a4,int a5,int from)
{if (mrk[a1][a2][a3][a4][a5][from])return f[a1][a2][a3][a4][a5][from];if (a1+a2+a3+a4+a5==0)return 1;LL ans=0;if (a1)ans+=(a1-(from==2))*cal(a1-1,a2,a3,a4,a5,1);if (a2)ans+=(a2-(from==3))*cal(a1+1,a2-1,a3,a4,a5,2);if (a3)ans+=(a3-(from==4))*cal(a1,a2+1,a3-1,a4,a5,3);if (a4)ans+=(a4-(from==5))*cal(a1,a2,a3+1,a4-1,a5,4);if (a5)ans+=a5*cal(a1,a2,a3,a4+1,a5-1,5);ans%=mod;mrk[a1][a2][a3][a4][a5][from]=1;f[a1][a2][a3][a4][a5][from]=ans;return f[a1][a2][a3][a4][a5][from];
}
int main()
{n=read();for (int i=1;i<=n;i++)rep[read()]++;printf("%lld\n",cal(rep[1],rep[2],rep[3],rep[4],rep[5],0));
}
转载于:https://www.cnblogs.com/zhber/p/4137348.html
bzoj1079 [SCOI2008]着色方案相关推荐
- bzoj1079: [SCOI2008]着色方案(DP)
1079: [SCOI2008]着色方案 题目:传送门 题解: DP刚神多年前讲过的一道神题. 二话不说,上来就是一个六维数组:F[i][a][b][c][d][e]//表示上一次涂的颜色是还剩下i次 ...
- [BZOJ1079][SCOI2008]着色方案 dp
1079: [SCOI2008]着色方案 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2368 Solved: 1428 [Submit][St ...
- bzoj1079: [SCOI2008]着色方案
1079: [SCOI2008]着色方案 Time Limit: 10 Sec Memory Limit: 162 MB Description 有n个木块排成一行,从左到右依次编号为1~n.你有k ...
- BZOJ1079 [SCOI2008]着色方案 记忆化搜索
1079: [SCOI2008]着色方案 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2826 Solved: 1682 [Submit][St ...
- bzoj 1079 [SCOI2008]着色方案
bzoj 1079 [SCOI2008]着色方案 Description 有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块.所有油漆刚好足够涂满所 ...
- BZOJ 1079: [SCOI2008]着色方案 记忆化搜索
1079: [SCOI2008]着色方案 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
- [SCOI2008]着色方案
这题也是看了别人题解也才会做的. 题解: 本题用的记忆优化搜索,题目说了给的颜色可以恰好图够所有木块. 题目给了能涂几块木块的颜色一共有几种.因为我们不可以连续图,所以我们把他分开来涂色. 用dp[a ...
- [SCOI2008]着色方案(DP)
题目链接 思想 显然我们后面的决策是跟前一步相关的,因此我们可以考虑DP,可以用一个15维的数组来进行转移,但是这样显然回mle,所以我们考虑如何压缩状态,由于1<=Ci<=51 < ...
- bzoj 1079: [SCOI2008]着色方案
思路:按个数分类dp 1 #include<bits/stdc++.h> 2 #define LL long long 3 #define fi first 4 #define se se ...
最新文章
- UITableView数据的添加、删除、移动
- Info:Memory module [DIMM] needs attention: Single-bit warning error rate exceeded, Single-bit fai...
- 第七章、Linux 文件与目录管理
- “Java是编译执行的语言”这句话对吗?
- sql优化的方法及思路_微生物发酵 技术优化思路 与方法
- HeartBeat 集群组件概述
- php xlsx里插入图片_常见的 PHP 面试题和答案分享
- 吃透web前端秘籍,来听听大佬是怎么说的
- html5 音乐转盘,HTML5 幸运大转盘
- win7下手动配置apache+ php + mysql 记
- DNW启动异常的问题
- 从load加载数据类型是struct说起
- python 基线拟合
- 在Silverlight中使用HierarchicalDataTemplate为TreeView实现递归树状结构
- bat批处理命令大全(翻译转载)
- [嗅探神器]Intercepter,支持当前所有流行OS
- c# wpf 利用截屏键实现截屏功能
- 集成灶哪个品牌性价比高质量好,过来人实话实说?
- ppt不能保存我html,powerpoint无法保存怎么解决
- 未来几年学什么设计更有前途?