hdu6899 Xor 2020ccpc network competition

http://acm.hdu.edu.cn/showproblem.php?pid=6899

During the game, I squatted for two hours, thinking about where I lost 1 last time, and then where I want to go this time. . . However, the more you write, the more chaotic you are, I didn’t even watch 0406.

It is said that it is an old question. Cometoj and previous dls questions have discussed |xy|, that is, the previous one is passed to the next one as -1 0 1, so that the carry of the subtraction can be guaranteed. See details Solution to this problem https://cometoj.com/contest/71/problem/D?problem_id=4019

Thank you hduoj for providing the admin account, go to the game ac code to learn

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int a,b,k,w;ll ans;
ll dp[35][3][3][2][2][2];

inline void prework()
{
	scanf("%d%d%d%d",&a,&b,&k,&w);
}

inline ll dfs(int ind,int v1,int v2,bool fa,bool fb,bool fw)
{
	v1=min(v1,1);v2=min(v2,1);
	if(v1<-1 || v2<-1) 
		return 0;
	if(ind<0) 
		return v1>=0 && v2>=0;
	if(dp[ind][v1+1][v2+1][fa][fb][fw]>=0)
		return dp[ind][v1+1][v2+1][fa][fb][fw];
	ll ret=0;
	int upa=fa?(a>>ind&1):1;
	int upb=fb?(b>>ind&1):1;
	int upw=fw?(w>>ind&1):1;
	int t=k>>ind&1;
	for(int i=0;i<=upa;i++)
		for(int j=0;j<=upb;j++)
		{
			if((i^j)>upw)
				continue;
			ret+=dfs(ind-1,v1*2+i-j+t,v2*2+j-i+t,fa&&i==upa,fb&&j==upb,fw&&(i^j)==upw);
		}
	return dp[ind][v1+1][v2+1][fa][fb][fw]=ret;
}

inline void mainwork()
{
	memset(dp,-1,sizeof(dp));
	ans=dfs(30,0,0,1,1,1);
}

inline void print()
{
	printf("%lld\n",ans);
}

int main()
{
	int t;
	scanf("%d",&t);
	for(int i=1;i<=t;i++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

 

Guess you like

Origin blog.csdn.net/liufengwei1/article/details/108720635