枚举。

看了这个方法:$http://www.cppblog.com/shiming413/archive/2008/12/21/29671.html$

将数字归类的地方不能用$vector$,会超时。$vector$换成数组就可以过,类似于邻接表。

因为题目给出的$16$个数字都是不同的,所以时间复杂度相对还比较低。

下面这组数据是极限数据,我的跑了$3800$$ms$。但测试数据中不会出现这样的数据。

$5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$ $5$

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} int a[],b[];
LL h[(<<)+]; struct X
{
int b, nx;
}e[];
int g[],k; void add(int a,int b)
{
e[k].b=b; e[k].nx=g[a]; g[a]=k++;
} int main()
{
int cas=;
while(~scanf("%d",&a[]))
{
if(a[]==) break;
for(int i=;i<=;i++) scanf("%d",&a[i]); k=; memset(g,-,sizeof g);
for(int i=;i<(<<);i++)
{
int t=i,cnt=;
for(int j=;j<;j++) if(i&(<<j)) b[cnt++]=j;
if(cnt!=) continue;
sort(b,b+);
do
{
add(*a[b[]]+*a[b[]]+*a[b[]]+*a[b[]],i);
}while(next_permutation(b,b+));
} memset(h,,sizeof h); for(int i=;i<=;i++)
{
for(int j=g[i];j!=-;j=e[j].nx)
{
for(int d=e[j].nx;d!=-;d=e[d].nx)
{
int f1=e[d].b,f2=e[j].b;
if(f1&f2) continue;
h[f1^f2]++;
}
}
} LL ans=;
for(int i=;i<(<<);i++)
{
int t=i,cnt=;
for(int j=;j<;j++) if(i&(<<j)) cnt++;
if(cnt!=) continue;
ans=ans+h[i]*h[(<<)--i];
}
printf("Case %d: %lld\n",cas++,ans/);
}
return ;
}

最新文章

  1. android——HttpUrlConnection
  2. IOS远程推送
  3. HTML5 标签audio添加网页背景音乐代码
  4. [应用][js+css3]3D盒子导航[PC端]
  5. RabbitMQ之前的那些事
  6. css 让内容满屏居中不变形
  7. 转:超链接a标签display属性的block和inline-block的用法说明
  8. C++学习50 对字符串流的读写
  9. [Ramda] Compose and Curry
  10. VS 2013的初配置
  11. js 闭包和回调
  12. iOS:点击button卡死
  13. 一起学JUCE之Atomic
  14. 一个小时学会MySQL数据库
  15. The Nerd Factor SPOJ - MYQ5
  16. [ExtJS5学习笔记]第十一节 Extjs5MVVM模式下系统登录实例
  17. Linux动态链接库的生成和使用
  18. HDU 3586 二分答案+树形DP判定
  19. webpack 应用笔记
  20. 20181223 python 使用Beautiful Soup

热门文章

  1. 在 Ubuntu 12.04 上通过 Tomcat 部署 Solr 4
  2. Unknown
  3. EF POWER TOOLS由数据库逆向CODE FIRST
  4. 学习Linux(一)环境搭建
  5. UIKit类结构图
  6. 使用 Entity Framework Code First
  7. poj1269
  8. ASP.NET MVC4简单使用ELMAH记录系统日志
  9. SSH使用技巧
  10. javascript 闭包基础分享