Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

终于知道啥叫状态压缩动态规划了

Posted by whosyourdaddy at 2010-07-13 07:13:15 on Problem 2411
也可以叫记忆化枚举吧。

网上找到一种方法,如果是横着的就定义11,如果竖着的定义为竖着的01,这样按行dp只需要考虑两件事儿,当前行&上一行,是不是全为1,不是说明竖着有空(不可能出现竖着的00),另一个要检查当前行里有没有横放的,但为奇数的1。

这个实现起来很简单啊。

inline bool check1(int in)
{
	int bit=0;
	while(in>0){
		if( (in&1)==1)
			bit++;
		else{
			if( (bit&1)==1)
				return false;
			bit=0;
		}
		in>>=1;
	}
	if( (bit&1)==1)
		return false;
	return true;
}

inline bool check2(int a, int b, int max)
{
	if( (a|b)!=max )
		return false;
	return check1(a&b);
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator