hdu 4272 2012长春赛区网络赛 dfs暴力 ***
2015-08-15 15:42
429 查看
总是T,以为要剪枝,后来发现加个map就行了
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> using namespace std; #define MOD 1000000007 const int INF=0x3f3f3f3f; const double eps=1e-5; typedef long long ll; #define cl(a) memset(a,0,sizeof(a)) #define ts printf("*****\n"); const int MAXN=1005; int n,m,tt; bool vis[MAXN]; int a[MAXN]; bool dfs(int pos) { while(vis[pos]==1&&pos>0) pos--; if(pos==0) return 1; if(pos==1) { return 0; } int temp=pos-1; for(int i=0;i<=5;i++) { if(temp<=0) return 0; if(vis[temp]) { i--; temp--; continue; } if(a[pos]==a[temp]) //找到 { vis[temp]=1; if(dfs(pos-1)) return 1; vis[temp]=0; } temp--; } return 0; } int main() { int i,j,k,ca=1; #ifndef ONLINE_JUDGE freopen("1.in","r",stdin); #endif while(scanf("%d",&n)!=EOF) { map<int,int> mp; for(i=1;i<=n;i++) { scanf("%d",a+i); mp[a[i]]++; } if(n%2) { printf("0\n"); continue; } bool f=1; map<int,int>::iterator it; for(it=mp.begin();it!=mp.end();it++) { if((it->second)%2==1) { f=0; break; } } if(!f) { printf("0\n"); continue; } cl(vis); printf("%d\n",dfs(n)); } }
相关文章推荐
- Android传统HTTP请求get----post方式提交数据(包含乱码问题)
- 大型网络游戏服务器的框架设计
- Ubuntu/centos网络接口没有eth0但是有eth1或eth2的问题
- http 自己组装格式
- 小言HTTP Authentication
- http请求获取到的网页源码是字节数组还是字符串?
- 谈谈对于vmware Workstation 网络连接三种模式的认识.
- 对偶传播神经网络(CPN)
- 学习向量量化神经网络
- 笔记本如何建立虚拟Wifi
- Recurrent Neural Network(循环神经网络)
- 跨物理节点的2层隔离网络--GRE通道
- TCP/IP协议学习之七(TCP的保活定时器keepalive选项)
- 学习SSO-1 Tomcat启用ssl(含有配置https时的异常解决)
- 网络安全系列之1:安全能力地图简介
- TCP/IP协议学习之六(RPC原理以及NFS协议)
- 网络流模板
- Thread:智能家庭无线mesh网络新标准
- ios文摘https和多线程
- TCP的服务流程