hdu 4272 2012长春赛区网络赛 dfs暴力 ***
总是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-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt;
bool vis[MAXN];
int a[MAXN];
bool dfs(int pos)
{
while(vis[pos]==&&pos>) pos--;
if(pos==) return ;
if(pos==)
{
return ;
}
int temp=pos-;
for(int i=;i<=;i++)
{
if(temp<=) return ;
if(vis[temp])
{
i--;
temp--;
continue;
}
if(a[pos]==a[temp]) //找到
{
vis[temp]=;
if(dfs(pos-)) return ;
vis[temp]=;
}
temp--;
}
return ;
}
int main()
{
int i,j,k,ca=;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
while(scanf("%d",&n)!=EOF)
{
map<int,int> mp;
for(i=;i<=n;i++)
{
scanf("%d",a+i);
mp[a[i]]++;
}
if(n%)
{
printf("0\n");
continue;
}
bool f=;
map<int,int>::iterator it;
for(it=mp.begin();it!=mp.end();it++)
{
if((it->second)%==)
{
f=;
break;
}
}
if(!f)
{
printf("0\n");
continue;
}
cl(vis);
printf("%d\n",dfs(n));
}
}
hdu 4272 2012长春赛区网络赛 dfs暴力 ***的更多相关文章
- hdu 4277 2012长春赛区网络赛 dfs+hashmap ***
hashmap判重大法好 #include<cstdio> #include<iostream> #include<algorithm> #include<c ...
- hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***
新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...
- hdu 4274 2012长春赛区网络赛 树形dp ***
设定每个节点的上限和下限,之后向上更新,判断是否出现矛盾 #include<cstdio> #include<iostream> #include<algorithm&g ...
- hdu 4741 2013杭州赛区网络赛 dfs ***
起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...
- hdu 4412 2012杭州赛区网络赛 期望
虽然dp方程很好写,就是这个期望不知道怎么求,昨晚的BC也是 题目问题抽象之后为:在一个x坐标轴上有N个点,每个点上有一个概率值,可以修M个工作站, 求怎样安排这M个工作站的位置,使得这N个点都走到工 ...
- hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***
题意: 有 n+1 个城市编号 0..n,有 m 条无向边,在 0 城市有个警察总部,最多可以派出 k 个逮捕队伍,在1..n 每个城市有一个犯罪团伙, 每个逮捕队伍在每个城市可以选 ...
- hdu 4293 2012成都赛区网络赛 dp ****
题意:有n个人,可任意分成若干组,然后每个人个各提供一个信息,表示他们组前面有多少人,后面有多少人.问最多有多少个信息是不冲突的. 将n个人看成一组区间,然后每个人的信息可以表示为该人所在组的区间,然 ...
- hdu 4291 2012成都赛区网络赛 矩阵快速幂 ***
分析:假设g(g(g(n)))=g(x),x可能非常大,但是由于mod 10^9+7,所以可以求出x的循环节 求出x的循环节后,假设g(g(g(n)))=g(x)=g(g(y)),即x=g(y),y也 ...
- hdu 4278 2012天津赛区网络赛 数学 *
8进制转为10进制 #include<cstdio> #include<iostream> #include<algorithm> #include<cstr ...
随机推荐
- Objective C 快速入门学习三
1.数据类型 和C语言基本一样. 有一个特别数据类型id,可以储存任何类型的对象,它是实现多态和动态绑定的基础. Objective-C 2.程序结构 Objective-C和C的程序结构一模一样,具 ...
- Linux Vsftpd 连接超时解决方法
Linux Vsftpd 连接超时解决方法 2013-11-13 10:58:34| 分类: 默认分类|举报|字号 订阅 解决方法(http://www.lingdus.com/thread ...
- 【SpringBoot】SpringBoot 入门示例
参考资料: http://www.tuicool.com/articles/mqeee2A http://www.cnblogs.com/suncj/p/4065589.html http://spr ...
- MQTT V3.1----publish解读
客户端/服务器的发布消息行为,与PUBLISH相关的消息类型: PUBLISH 客户端发布消息经由服务器分发到所有对应的订阅者那里.一个订阅者可以订阅若干个主题(Topic name),但一个PUBL ...
- poj 1562
这道题主要注意输入的问题,以及对周围搜索时的注意,要使用递归,多次调用,附上一组数据 11 20*@*@*@@@**@*@**@@@*****@*@*@*@*@****@**@*@*@*@*@*@*@ ...
- cat -n与nl的区别
cat -n filename:空行也算一行 nl filename:空行不算一行
- net use与shutdown配合使用,本机重启远程服务器
net use与shutdown配合使用,本机重启远程服务器 今天服务器出现问题了,能ping通,但就是远程登录服务器后,服务器无法响应. 在本机测试发现ftp服务可以使用,于是就想通过ftp ...
- 新浪微博授权失败:applications over the unaudited use restrictions
在用新浪微博授权第三方app时,授权失败,log显示 com.sina.weibo.sdk.exception.WeiboHttpException: {,"request":&q ...
- 【leetcode】Binary Tree Level Order Traversal I & II
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- php生成对象的研究
<?php abstract class E{ protected $name; function __construct($name){ $this->name = $name; } a ...