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 phython at 2017-03-08 21:26:31 on Problem 2411
#include <cstdio>
#include <iostream>
#include <algorithm> 
#include <cstring>
using namespace std; 
#define int long long
int dp[1<<13][13];
int cnt;
int N,M;
bool check(int x)
{
	int flag = 0;
	for(int i = 0;i < M;i++)
	{
		if((x&1) == 0) flag ++;
		else if(flag%2 != 0) return false;
		x >>= 1;
	}
	if(flag%2 != 0) return false;
	return true;
}
main()
{
	while(cin>>N>>M&&N+M)
	{
		memset(dp,0,sizeof(dp));
		int res = 0;
		int pres = 0;
		for(int S = 0;S < 1<<M;++S) if(check(S)) {dp[S][0] = 1;if(!S) pres++;}
		for(int i = 1;i < N-1;i++)
			for(int S = 0;S < 1<<M;S++)
				for(int pS = 0;pS < 1<<M;pS++)
					if((pS&S) == 0 && check(S|pS)) dp[S][i] += dp[pS][i-1];
					
		for(int S = 0;S < 1<<M;S++)	if(check(S)) res += dp[S][N-2];
		if(N==1) cout<<pres<<endl;
		else cout<<res<<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