题目大意:有不超过14个点组成的完全图,给出邻接矩阵,问是否存在长度为W的欧拉回路?

     数据范围:n<=14, w<=1e15;

     standard input/output 7 s, 256 MB

分析:直接暴力是14!的复杂度,显然不能通过;

   考虑折半搜索,我们取0号点为起点,然后把所有的点分成两半;

   两边分别暴力跑,最后检查一边,看另一边是否有可行的路径即可;

   复杂度为C(N,N/2)*(n/2)!;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=(int)n;i++)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
#define ls (rt<<1)
#define rs (rt<<1|1)
#define all(x) x.begin(),x.end()
const int maxn=1e5+;
const int N=4e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qmul(ll p,ll q,ll mo){ll f=;while(q){if(q&)f=(f+p)%mo;p=(p+p)%mo;q>>=;}return f;}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,c[];
ll w,d[][];
set<ll>dp[];
bool flag;
void dfs(int pos,int sta,ll now,int lim,int tp)
{
if(flag)return;
int i;
sta|=(<<pos);
if(lim==)
{
if(tp==)
{
rep(i,,n-)
{
if(c[tp]>>i&)continue;
if(dp[i].find(w-now-d[i][pos])!=dp[i].end())
{
flag=true;
return;
}
}
}
else dp[pos].insert(now);
return;
}
rep(i,,n-)
{
if((sta>>i&)||(c[tp]>>i&)==)continue;
dfs(i,sta,now+d[pos][i],lim-,tp);
}
}
int main(){
int i,j;
scanf("%d%lld",&n,&w);
rep(i,,n-)rep(j,,n-)scanf("%lld",&d[i][j]);
if(n==)
{
if(d[][]+d[][]==w)puts("possible");
else puts("impossible");
}
else
{
int all=((<<n)-);
for(i=all-;i;i=((i-)&all))
{
if(__builtin_popcount(i)!=n/)continue;
c[]=c[]=;
rep(j,,n-)
{
if(i>>j&)c[]|=(<<j);
else c[]|=(<<j);
}
dfs(,,,n/,);
dfs(,,,n--n/,);
rep(j,,n-)dp[j].clear();
if(flag)break;
}
puts(flag?"possible":"impossible");
}
return ;
}

UVALIVE 6958 Indoorienteering的更多相关文章

  1. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  2. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  3. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  4. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  5. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  6. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  7. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

  8. UVALive 6948 Jokewithpermutation dfs

    题目链接:UVALive 6948  Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...

  9. 【暑假】[实用数据结构]UVAlive 3135 Argus

    UVAlive 3135 Argus Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

随机推荐

  1. PCB javascript实现个税5000计算

    个税调整为5000计划实施是今年10月份.而明年一月份全面实施, 马上快到5000个税实施的日子了,当到了个税实施日子时,必定网络会产生热点,这个时候需要就是蹭热点的时候到来时. 全国网友肯定都会关心 ...

  2. jquery得到焦点和失去焦点

    鼠标在搜索框中点击的时候里面的文字就消失了,经常会用到搜索框的获得焦点和失去焦点的事件,接下来介绍一下具体代码,感兴趣的朋友额可以参考下   input失去焦点和获得焦点 鼠标在搜索框中点击的时候里面 ...

  3. 异常强大的Markdown编辑插件-Markdown Preview Enhanced

    最近使用Markdown写作,了解到以下这些Markdown写作工具 MaHua 在线markdown编辑器 百度搜索Markdown时,它排在非常靠前的位置 马克飞象- 专为印象笔记打造的Markd ...

  4. SpringBoot2.0整合SpringSecurity实现自定义表单登录

    我们知道企业级权限框架一般有Shiro,Shiro虽然强大,但是却不属于Spring成员之一,接下来我们说说SpringSecurity这款强大的安全框架.费话不多说,直接上干货. pom文件引入以下 ...

  5. hcode视频教程中心(学习h5和hbuilder等)

    网站: http://www.hcoder.net/course

  6. Coursera公开课-Machine_learing:编程作业3

    第四周 编程作业: Multi-class Classification and Neural Networks 这周作业与上一周有许多相同的部分,比如longistic regression中的lr ...

  7. 15年用canvas画的

    请恕我当年的工作太轻松,用canvas手打了一个图,技术含量并没有什么,现在看看,甚是怀念_(¦3」∠)_ <!DOCTYPE html> <html> <head&g ...

  8. 深入理解async和await的作用及各种适用场景和用法

    https://www.cnblogs.com/yaopengfei/archive/2018/07/02/9249390.html https://www.cnblogs.com/xianyudot ...

  9. [ NOIP 2008 ] TG

    \(\\\) \(\#A\) \(Word\) 给出一个长为\(N\)的小写字母串,判断出现所有字母中最多出现次数减最少出现次数得到的答案是否是质数. \(N\in [1,100]\) 直接按题意开桶 ...

  10. (转)Hibernate框架基础——cascade属性

    http://blog.csdn.net/yerenyuan_pku/article/details/52760010 我们以部门和员工的关系为例讲解一对多关联关系映射时,删除部门时,如果部门有关联的 ...