`
promiser
  • 浏览: 77239 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

bzoj1079: [SCOI2008]着色方案

    博客分类:
  • oi
 
阅读更多

我写的是状态压缩DP(其实没有必要),所有的燃料其实都可以按照能够染多少格子来划分种类,那至多只有5种染料,马上状压(也不算状压,记忆化搜索吧)

const int N = 20, Mod = 1000000007;
map<int, int> Dp;
map<int, bool> Vis;
int n, Dat[6], St, Base[6];

inline void Input() {
	int x;
	for(scanf("%d", &n); n--; ) scanf("%d", &x), Dat[x]++;
	For(i, 1, 5) St = St * 20 + Dat[i];
	Ford(i, 5, 1) Base[i] = (i == 5 ? 20 : Base[i + 1] * 20);
}

inline int Search(int State) {
	bool &Hash = Vis[State];
	int &Now = Dp[State], t, Last = State % 20;
	if(Hash) return Now;
	if(State / 20 == 0) return 1;
	LL Ret = 0;
	For(i, 1, 5)
		if(t = ((State / Base[i]) % 20))
			Ret += (LL) (t - (Last == i + 1)) * Search(State - Base[i] + Base[i - 1] - Last + i);
	return Hash = 1, Now = Ret % Mod;
}

inline void Solve() {
	printf("%d\n", Search(St * 20));
}

int main() {
	#ifndef ONLINE_JUDGE
	SETIO("1079");
	#endif
	Input();
	Solve();
	return 0;
}

 

 

0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics