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个木块排成一 ...
随机推荐
- Codeforces Round #346 (Div. 2) E - New Reform 无相图求环
题目链接: 题目 E. New Reform time limit per test 1 second memory limit per test 256 megabytes inputstandar ...
- ExtJS4.2学习(13)基于表格的扩展插件---rowEditing
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-24/182.html --------------- ...
- WEB开发者必备的7个JavaScript函数
防止高频调用的debounce函数 这个 debounce 函数对于那些执行事件驱动的任务来说是必不可少的提高性能的函数.如果你在使用scroll, resize, key*等事件触发执行任务时不使用 ...
- PE 文件
一.PE文件基本结构 上图便是PE文件的基本结构.(注意:DOS MZ Header和部分PE header的大小是不变的:DOS stub部分的大小是可变的.) 二.Section 详解 一个PE文 ...
- XoftSpy 4.13的注册算法分析
[标题]XoftSpy 4.13的注册算法分析 [作者]forever[RCT] [语言]VC [工具]ida4.6,ollydbg1.1 [正文] 这个软件的算法很简单,正好拿来做逆向分 ...
- spoj 665
直接判 没什么算法 也没什么技巧 水水~~ #include <cstdio> #include <cstring> #include <algorithm> ...
- 【leetcode】Combination Sum II (middle) ☆
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- 在线学习SQL语句?没问题~~
以前弄得少,没注意.. http://sqlfiddle.com/ CREATE TABLE Presidents ( Id INT UNSIGNED NOT NULL AUTO_INCREMENT, ...
- thinkphp 分组
分组 配置项: // 开启分组 'APP_GROUP_LIST'=>'Home,Admin', // 默认分组 'DEFAULT_GROUP'=>'Home', 涉及分组: 配置文件分组, ...
- Servlet课程0424(三) 通过继承HttpServlet来开发Servlet
//这是第三种开发servlet的方法,通过继承httpservlet package com.tsinghua; import javax.servlet.http.*; import java.i ...