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

言简意赅地AC

Posted by lanmao45 at 2014-12-11 21:27:54 on Problem 2411
#include<iostream>
#include<cstring>
using namespace std;
long long dp[20][1<<11];
int n,m;
void dfs(int s,int row,int line,long long val)
{
	int i,k;
	k=m-1;
	dp[row][line]+=val;
	for(i=s;i<k;i++)
		if((line>>i&1)==0)
			if((line>>i+1&1)==0)
				dfs(i+2,row,line|(1<<i)|(1<<i+1),val);
}
int main()
{
	int i,j,k;
	while(cin>>n>>m)
	{
		if(n==0&&m==0)
			break;
		memset(dp,0,sizeof(dp));
		dfs(0,0,0,1);
		k=1<<m;
		for(i=1;i<n;i++)
			for(j=0;j<k;j++)
				dfs(0,i,k-1^j,dp[i-1][j]);
		cout<<dp[n-1][k-1]<<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