A Simple Task CodeForces - 11D

题意:输出一个无向图的简单环数量。简单环指无重复边的环。保证图无重边自环。

ans[i][j]表示"包含i中的点,以i中第一个点为起点,以j为终点"的路径条数。

对于某个i,枚举当前终点j(显然不能是首个点),产生一个状态。再枚举上一次终点k,如果能转移就转移。

如果i中点数大于2且j到i中第一个点有路,就认为产生了环。最后每个环记录了两遍,要除以2。

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n,m;
bool ok[][];
LL ans[][];
LL anss;
int main()
{
LL a,b,i,j,k,fi,p,pp;
scanf("%lld%lld",&n,&m);
for(i=;i<=m;i++)
{
scanf("%lld%lld",&a,&b);
ok[a][b]=ok[b][a]=true;
}
for(i=;i<(<<n);i++)
{
pp=__builtin_popcountll(i);
if(pp==)
{
//for(j=1;j<=n;j++)
ans[i][__builtin_ffsll(i)]=;
}
else
{
fi=__builtin_ffsll(i);
for(j=;j<=n;j++)
if((i&(<<(j-)))&&j!=fi)
{
p=i^(<<(j-));
for(k=;k<=n;k++)
if((p&(<<(k-)))&&ok[k][j])
{
ans[i][j]+=ans[p][k];
}
if(ok[j][fi]&&pp>) anss+=ans[i][j];
} }
}
printf("%lld",anss/);
return ;
}
/*
http://blog.csdn.net/fangzhenpeng/article/details/49078233
http://blog.csdn.net/tobewhatyouwanttobe/article/details/38036129
http://blog.csdn.net/kk303/article/details/9621933
http://blog.csdn.net/dreamon3/article/details/51347151
*/

稍稍改进了

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n,m;
bool ok[][];
LL ans[][];
LL anss;
int main()
{
LL a,b,i,j,k,fi,p,pp;
scanf("%lld%lld",&n,&m);
for(i=;i<=m;i++)
{
scanf("%lld%lld",&a,&b);
ok[a][b]=ok[b][a]=true;
}
for(i=;i<(<<n);i++)
{
pp=__builtin_popcountll(i);
fi=__builtin_ffsll(i);
if(pp==)
ans[i][fi]=;
else
{
for(j=fi+;j<=n;j++)
if((i&(<<(j-))))
{
p=i^(<<(j-));
for(k=;k<=n;k++)
if((p&(<<(k-)))&&ok[k][j])
ans[i][j]+=ans[p][k];
if(ok[j][fi]&&pp>) anss+=ans[i][j];
} }
}
printf("%lld",anss/);
return ;
}
/*
http://blog.csdn.net/fangzhenpeng/article/details/49078233
http://blog.csdn.net/tobewhatyouwanttobe/article/details/38036129
http://blog.csdn.net/kk303/article/details/9621933
http://blog.csdn.net/dreamon3/article/details/51347151
*/

A Simple Task CodeForces - 11D的更多相关文章

  1. 计数排序 + 线段树优化 --- Codeforces 558E : A Simple Task

    E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作, ...

  2. Codeforces 558E A Simple Task (计数排序&&线段树优化)

    题目链接:http://codeforces.com/contest/558/problem/E E. A Simple Task time limit per test5 seconds memor ...

  3. Codeforces Round #312 (Div. 2) E. A Simple Task 线段树

    E. A Simple Task 题目连接: http://www.codeforces.com/contest/558/problem/E Description This task is very ...

  4. Codeforces Round #312 (Div. 2) E. A Simple Task 线段树+计数排序

    题目链接: http://codeforces.com/problemset/problem/558/E E. A Simple Task time limit per test5 secondsme ...

  5. Codeforces C. A Simple Task(状态压缩dp)

    题目描述:  A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  6. Codeforces 558E A Simple Task(权值线段树)

    题目链接  A Simple Task 题意  给出一个小写字母序列和若干操作.每个操作为对给定区间进行升序排序或降序排序. 考虑权值线段树. 建立26棵权值线段树.每次操作的时候先把26棵线段树上的 ...

  7. Codeforces Round #312 (Div. 2) E. A Simple Task 线段树 延时标记

    E. A Simple Task time limit per test5 seconds memory limit per test512 megabytes inputstandard input ...

  8. HDU-1339 A Simple Task

    http://acm.hdu.edu.cn/showproblem.php?pid=1339 正常做法超时,要有点小技巧存在. A Simple Task Time Limit: 2000/1000 ...

  9. A Simple Task

    A Simple Task Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

随机推荐

  1. Org-mode五分钟教程ZZZ

    Table of Contents 1 源起 2 简介 2.1 获取 org-mode 2.2 安装 3 基础用法 3.1 创建一个新文件 3.2 简单的任务列表 3.3 使用标题组织一篇文章 3.4 ...

  2. flask-admin的学习使用

    参考: 1.https://blog.igevin.info/wechats/wechat-flask-admin/ 2.http://flask-admin.readthedocs.io/en/la ...

  3. 利用Druid实现应用和SQL监控

    一.关于Druid Druid是一个JDBC组件,它包括三部分: DruidDriver 代理Driver,能够提供基于Filter-Chain模式的插件体系. DruidDataSource 高效可 ...

  4. libsvm源码凝视+算法描写叙述:svm_train

    (I will try my best to make this note clearer. We mainly focus on solve_c_svc in this note) We mainl ...

  5. Android从无知到有知——NO.6

    紧随上一篇,说一下创建ip拨号器过程中出现的一些问题. 1)在一開始监听外拨电话的时候会报这样一个警告: Permission Denial: receiving Intent { act=andro ...

  6. java递归删除文件及目录

    package base; import java.io.File; public class delete {     public static void main(String[] args) ...

  7. Visual Studio 2012 Fakes框架测试驱动开发TDD教程

    一.前言 最近团队要尝试TDD(测试驱动开发)的实践,很多人习惯了先代码后测试的流程,对于TDD总心存恐惧,认为没有代码的情况下写测试代码时被架空了,没法写下来,其实,根据个人实践经验,TDD并不可怕 ...

  8. 关于OutOfMemoryError的处理

    转自:http://www.blogjava.net/rosen/archive/2010/05/21/321575.html http://www.blogjava.net/rosen/archiv ...

  9. 关于axis2.1.6与websphere7的包冲突问题的解决方式

    1,复制axis2.1.6内的module目录内的全部文件到lib 并改动扩展名为.jar 2,删除module目录(可选,不删除也能够) 3,部署到was 4,设置was相应应用程序的类载入方案为父 ...

  10. Fluently NHibernate映射多个实体程序集

    Fluently NHibernate有个好处就是可以在代码里定义实体类,而不必写冗长的XML. 但通常,一个项目对应的所有的实体类,都编译成一个DLL.如果有个项目,是在某个父项目的基础上再扩展,那 ...