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个木块排成一 ...
随机推荐
- Extjs4.2——Panel
一.Panel的border属性: 示例: Ext.create('Ext.panel.Panel', { title: 'Hello', width: 200, height:100, border ...
- js检测对象的类型
在JavaScript中,想要判断某个对象值属于哪种内置类型,最靠谱的做法就是通过Object.prototype.toString方法. 示例: var array=[1,2,3]; Object. ...
- fiddler 插件开发二
本篇主要讲解Fildder插件开发中的涉及到的主要接口与类. 1.IFiddlerExtension 接口 如果要开发的自定义插件有UI界面,则需要实现IFiddlerExtension 接口.你程序 ...
- POJ3207+tarjan+2-sat
/* 2-sat 题意:给定一个圆,圆上一些点.两点一线.现给出一些线,这些线可以在圆内连起来,也可以在圆外. 问有没有可能所有的线画完 且 不出现相交. 思路:把线画在圆内或圆外 看成一个组合.其它 ...
- MVC 文件上传和图片剪辑
http://www.cnblogs.com/hinton/archive/2012/03/01/2375465.html http://gallery.kissyui.com/uploader/1. ...
- highcharts 切换
<!doctype html> <html lang="en"> <head> <script type="text/javas ...
- codeforces #305 div1 done
总算搞定了这一场比赛的题目,感觉收获蛮大 其中A,B,C都能通过自己的思考解决掉 D题思路好神,E题仔细想想也能想出来 以后坚持每两天或者一天做一场CF的div1的全套题目 除非有实在无法做出来的题目 ...
- Spring MVC 与 web开发
转载:http://coderbee.net/index.php/java/20140719/959 项目组用了 Spring MVC 进行开发,觉得对里面的使用方式不是很满意,就想,如果是我来搭建开 ...
- Android ImageView(纯java)
import android.app.Activity; import android.graphics.*; import android.graphics.drawable.*; import a ...
- C语言字符串函数
strtok() 字符串分割函数strstr() 字符串查找函数 范例 #include <string.h> main() { char * s = " ...