BZOJ 1079 [SCOI2008]着色方案
http://www.lydsy.com/JudgeOnline/problem.php?id=1079
思路:如果把每种油漆看成一种状态,O(5^15)不行
DP[a][b][c][d][e][f]:a表示能凃一个的有多少个
b能凃2个的还有多少个
c能凃3个的还有多少个
d能凃4个的还有多少个
e能凃5个的还有多少个
last 上次凃的是:last个油漆。
所以这次如果选last-1个油漆的时候,数量还要减一,与上次不同
//#pragma comment(linker, "/STACK:167772160")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
// #include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
void fre() { freopen("in.txt","r",stdin);}
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
// const double pi = acos(-1);
const LL mod = 1e9+;
inline int r(){
int x=,f=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int A[];
LL dp[][][][][][];
bool vis[][][][][][]; LL work(int a,int b,int c,int d,int e,int last){
LL tem;
tem=;
if((a|b|c|d|e)==) return ;
if(vis[a][b][c][d][e][last]) return dp[a][b][c][d][e][last];
if(a)
tem+=(a-(last==))*work(a-,b,c,d,e,);
if(b)
tem+=(b-(last==))*work(a+,b-,c,d,e,);
if(c)
tem+=(c-(last==))*work(a,b+,c-,d,e,);
if(d)
tem+=(d-(last==))*work(a,b,c+,d-,e,);
if(e)
tem+=e*work(a,b,c,d+,e-,);
dp[a][b][c][d][e][last]=(tem%mod);
vis[a][b][c][d][e][last]=true;
return dp[a][b][c][d][e][last];
} int main(){
// fre();
int n;
while(~scanf("%d",&n)){
// clc(dp,0);
// clc(vis,0);
// clc(A,0);
for(int i=;i<n;i++){
int x;
x=r();
A[x]++;
}
LL ans;
ans=work(A[],A[],A[],A[],A[],);
cout<<ans<<endl;
}
return ;
}
BZOJ 1079 [SCOI2008]着色方案的更多相关文章
- BZOJ 1079: [SCOI2008]着色方案 记忆化搜索
1079: [SCOI2008]着色方案 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
- bzoj 1079: [SCOI2008]着色方案 DP
1079: [SCOI2008]着色方案 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 803 Solved: 512[Submit][Status ...
- BZOJ 1079: [SCOI2008]着色方案(巧妙的dp)
BZOJ 1079: [SCOI2008]着色方案(巧妙的dp) 题意:有\(n\)个木块排成一行,从左到右依次编号为\(1\)~\(n\).你有\(k\)种颜色的油漆,其中第\(i\)种颜色的油漆足 ...
- bzoj 1079: [SCOI2008]着色方案【记忆化搜索】
本来打算把每个颜色剩下的压起来存map来记忆化,写一半发现自己zz了 考虑当前都能涂x次的油漆本质是一样的. 直接存五个变量分别是剩下12345个格子的油漆数,然后直接开数组把这个和步数存起来,记忆化 ...
- 【BZOJ】1079: [SCOI2008]着色方案(dp+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1079 只能想到5^15的做法...........................果然我太弱. 其实 ...
- 1079: [SCOI2008]着色方案
链接 思路 首先是dp,如果直接用每个种颜色的剩余个数做状态的话,复杂度为5^15. 由于c<=5,所以用剩余数量的颜色的种类数做状态:f[a][b][c][d][e][last]表示剩余数量为 ...
- bzoj1079: [SCOI2008]着色方案
ci<=5直接想到的就是5维dp了...dp方程YY起来很好玩...写成记忆化搜索比较容易 #include<cstdio> #include<cstring> #inc ...
- [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个木块排成一 ...
随机推荐
- MySQL Replication 常用架构
转自: http://www.cnblogs.com/ggjucheng/archive/2012/11/13/2768879.html 前言 MySQLReplicaion本身是一个比较简单的架构, ...
- BZOJ 1706: [usaco2007 Nov]relays 奶牛接力跑
Description FJ的N(2 <= N <= 1,000,000)头奶牛选择了接力跑作为她们的日常锻炼项目.至于进行接力跑的地点 自然是在牧场中现有的T(2 <= T < ...
- VIM的高级使用
VIM的高级使用 转:http://www.cnblogs.com/itech/archive/2012/02/22/2363111.html 1)一些常用的Vim配置,在~/.vimrc中 syn ...
- Visual C++ unicode and utf8 转换
ATL宏: USES_CONVERSION; W2A A2W CString StringUtil::UTF8_to_UNICODE(const char *utf8_string, int leng ...
- 【leetcode】4Sum(middle)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...
- POJ2348+博弈
/* 博弈 关键态:较大数是较小数的2倍以上. */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...
- (转)Android系统自带样式(@android:style/)
在AndroidManifest.xml文件的activity中配置 1.android:theme="@android:style/Theme" 默认状态,即如果theme这里不 ...
- pmf,cpmf,pdf,cdf,iid的解释
- forks rate异常
一.收到nagios Current_load报警短信
- Vim Gtags插件
01.Gtags func:查看定义处 02.Gtags -r func:查看引用处 03.Gtags -s text:查看未被数据库定义的tags 04.copen:打开quick fix显示窗口 ...