hdu5305(状压dp)

这状压dp还是比较好的。。思维上有点难度。。。

目标是使该点连的黑/白边数为度数的一半。。考虑到度数不超过8,那么边数自然也不超过4,所以只要用2位二进制来表示连的黑边数。。

然后转移就可以随便转移。。主要是在二进制部分位的提取和替换。。



/**
 *          ┏┓    ┏┓
 *          ┏┛┗━━━━━━━┛┗━━━┓
 *          ┃       ┃  
 *          ┃   ━    ┃
 *          ┃ >   < ┃
 *          ┃       ┃
 *          ┃... ⌒ ...  ┃
 *          ┃              ┃
 *          ┗━┓          ┏━┛
 *          ┃          ┃ Code is far away from bug with the animal protecting          
 *          ┃          ┃   神兽保佑,代码无bug
 *          ┃          ┃           
 *          ┃          ┃        
 *          ┃          ┃
 *          ┃          ┃           
 *          ┃          ┗━━━┓
 *          ┃              ┣┓
 *          ┃              ┏┛
 *          ┗┓┓┏━━━━━━━━┳┓┏┛
 *           ┃┫┫       ┃┫┫
 *           ┗┻┛       ┗┻┛
 */ 
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-12
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 205
#define nm 100005
#define pi 3.1415926535897931
const ll inf=1000000007;
using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}




int n,m,c[nm],d[nm],_x,_y,s,tot,b[NM];
int main(){
    int _=read();while(_--){
	n=read();m=read();mem(c);mem(b);mem(d);
	tot=succ(n*2)-1;s=0;
	c[0]=1;
	inc(i,1,m){
	    _x=read();_y=read();b[_x]++;b[_y]++;
	    inc(j,0,tot)if(c[j]){
		int x=2*!!(j&succ(2*_x-1))+!!(j&succ(2*_x-2));
		int y=2*!!(j&succ(2*_y-1))+!!(j&succ(2*_y-2));
		int dx=(j&succ(2*_x-1))+(j&succ(2*_x-2));
		int dy=(j&succ(2*_y-1))+(j&succ(2*_y-2));
		//printf("%d %d %d %d %d\n",j,dx,dy,x,y);
		x++;y++;
		if(x<5&&y<5)d[j^dx^dy^(x*succ(2*_x-2))^(y*succ(2*_y-2))]+=c[j];
	    }
	    inc(j,0,tot)c[j]=d[j]+c[j],d[j]=0;
	}
	bool f=false;
	inc(i,1,n)if(b[i]%2){f=true;break;}else s+=(b[i]/2)*succ(i*2-2);
	if(!f)printf("%d\n",c[s]);else printf("0\n");
    }
    return 0;
}




Friends

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2705    Accepted Submission(s): 1299


Problem Description
There are n people and m pairs of friends. For every pair of friends, they can choose to become online friends (communicating using online applications) or offline friends (mostly using face-to-face communication). However, everyone in these n people wants to have the same number of online and offline friends (i.e. If one person has x onine friends, he or she must have x offline friends too, but different people can have different number of online or offline friends). Please determine how many ways there are to satisfy their requirements.
 

Input
The first line of the input is a single integer T (T=100), indicating the number of testcases.

For each testcase, the first line contains two integers n (1n8) and m (0mn(n1)2), indicating the number of people and the number of pairs of friends, respectively. Each of the next m lines contains two numbers x and y, which mean x and y are friends. It is guaranteed that xy and every friend relationship will appear at most once.
 

Output
For each testcase, print one number indicating the answer.
 

Sample Input
 
 
2 3 3 1 2 2 3 3 1 4 4 1 2 2 3 3 4 4 1
 

Sample Output
 
 
0 2
 

Author
XJZX
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   6297  6296  6295  6294  6293 
 

Statistic |  Submit |  Discuss | Note
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值