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

4 11竟然是20299607

Posted by binlong at 2012-10-29 09:48:52 on Problem 2411
怎么回事?用的状态压缩DP。。。。


#include<iostream>
using namespace std;

int judge( int state)
{
	int cnt = 0;
	while(state)
	{
		if(state&1) ++cnt;//该处是用于计数
		else
		{
			//该处判断奇偶,若为奇数个连续的1则为非法状态
			if( cnt & 1) return 0;
			cnt = 0;//因为只计连续的,故重置
		}
		state>>=1;
	}
	if( cnt & 1) return 0;
	return 1;
}


int main()
{
	int row, col ;
	long long dp[12][2050];
	long long  FULL = 0;
	while( cin>>row>>col && row && col)
	{
		//乘积为奇数则无法完全覆盖
		if(  (row*col)&1 )
		{
			cout<<0<<endl;
			continue;
		}
		memset(dp,0, sizeof(dp) );
		//行为线性,列为指数,故交换优化性能
		if(row < col)
		{
			int t = row; row = col; col = t;
		}
		FULL = (1<<col) - 1;
		
		for(int state = 0; state <= FULL; ++state)
		{
			if(  judge(state) )
				dp[0][state] = 1;
		}

		for(int i = 1; i != row; ++i)
		{
			for(int state = 0; state <= FULL; ++state)
				for(int last = 0; last <= FULL; ++last)
					if(  judge( last&state) && (last|state==FULL)  )
						dp[i][state] += dp[i-1][last];
		}
		cout<<dp[row-1][FULL]<<endl;
	}
	return 0;
}

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