Codeforces 11D A Simple Task 统计简单无向图中环的个数(非原创)
太难了,学不会。看了两天都会背了,但是感觉题目稍微变下就不会了。dp还是摸不到路子。
附ac代码:
1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 #include<vector>
6 using namespace std;
7 typedef long long ll;
8 ll dp[1<<20][20],ans=0;
9 vector<int>e[20];
10 int lowbit(int x)
11 {
12 return x&(-x);
13 }
14 int main()
15 {
16 ios::sync_with_stdio(false);
17 int n,m,f,t;
18 cin>>n>>m;
19 for(int i=0;i<m;++i)
20 {
21 cin>>f>>t;
22 e[f-1].push_back(t-1);
23 e[t-1].push_back(f-1);
24 }
25 for(int i=0;i<n;++i)
26 dp[1<<i][i]=1;
27 for(int sta=1;sta<(1<<n);sta++)
28 {
29 for(int i=0;i<n;++i)
30 {
31 if(dp[sta][i])
32 {
33 for(int k=0;k<e[i].size();++k)
34 {
35 int j=e[i][k];
36 if(lowbit(sta)>(1<<j)) //如果该点比第一个点还要小,就跳过
37 continue;
38 if(sta&(1<<j))
39 {
40 if(lowbit(sta)==(1<<j))//如果i和该状态的起点(即最低位)联通,则记录
41 ans+=dp[sta][i];
42 }
43 else
44 {
45 dp[sta|(1<<j)][j]+=dp[sta][i];//否则转移状态
46 }
47 }
48 }
49 }
50 }
51 ans=(ans-m)/2;
52 cout<<ans<<endl;
53 return 0;
54 }
附学习博客:http://blog.csdn.net/fangzhenpeng/article/details/49078233
Codeforces 11D A Simple Task 统计简单无向图中环的个数(非原创)的更多相关文章
- [CodeForces 11D] A Simple Task - 状态压缩入门
状态压缩/Bitmask 在动态规划问题中,我们会遇到需要记录一个节点是否被占用/是否到达过的情况.而对于一个节点数有多个甚至十几个的问题,开一个巨型的[0/1]数组显然不现实.于是就引入了状态压缩, ...
- CodeForces - 11D A Simple Task
Discription Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycl ...
- Codeforces C. A Simple Task(状态压缩dp)
题目描述: A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 计数排序 + 线段树优化 --- Codeforces 558E : A Simple Task
E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作, ...
- Codeforces 558E A Simple Task (计数排序&&线段树优化)
题目链接:http://codeforces.com/contest/558/problem/E E. A Simple Task time limit per test5 seconds memor ...
- Codeforces 558E A Simple Task(权值线段树)
题目链接 A Simple Task 题意 给出一个小写字母序列和若干操作.每个操作为对给定区间进行升序排序或降序排序. 考虑权值线段树. 建立26棵权值线段树.每次操作的时候先把26棵线段树上的 ...
- Codeforces J. A Simple Task(多棵线段树)
题目描述: Description This task is very simple. Given a string S of length n and q queries each query is ...
- Codeforces 558E A Simple Task(计数排序+线段树优化)
http://codeforces.com/problemset/problem/558/E Examples input 1 abacdabcda output 1 cbcaaaabdd input ...
- CodeForces 588E A Simple Task(线段树)
This task is very simple. Given a string S of length n and q queries each query is on the format i j ...
随机推荐
- 1.2V升压到3V和3.3V的升压芯片
1.2V镍氢电池升压到3V和3.3V输出,1.2V升压3V,1.2V升压3.3V稳压输出供电的芯片. PW5100 是一款低静态电流.达效率. PFM 模式控制的同步升压变换器. PW5100 所需的 ...
- 镍氢可充电电池2.4V转3.3V,2V转3.3V稳压供电输出电路图
PW5100可以实现2.4V转3.3V,2V转3.3V的稳压电源电路,输出电流500MA.静态电流10uA,SOT23-5封装.输出纹波低,轻载性能高(轻载电感推荐6.8UH-10UH). PW510 ...
- DSL是什么?Elasticsearch的Query DSL又是什么?
1.DSL简介 DSL 其实是 Domain Specific Language 的缩写,中文翻译为领域特定语言.而与 DSL 相对的就是 GPL,这里的 GPL 并不是我们知道的开源许可证(备注:G ...
- 2021年【线上】第一性原理vasp技术实战培训班
材料模拟分子动力学课程 3月19号--22号 远程在线课 lammps分子动力学课程 3月12号--15号 远程在线课 第一性原理VASP实战课 3月25号-28号 远程在线课 量子化学Gaussia ...
- cisco交换机路由器静态路由配置
一.切换模式 router>en //用户模式enable router#conf t //特权模式 ...
- Windows server 2008常用优化设置
1. 如何取消开机按 CTRL+ALT+DEL登录? 控制面板→管理工具→本地安全策略→本地策略→安全选项→交互式登录:无须按CTRL+ALT+DEL→启用. 2. 如何取消关机时出现的关机理由选择项 ...
- ValueError: the environment variable is longer than 32767 characters On Windows, an environment variable string ("name=value" string) is limited to 32,767 characters
https://github.com/python/cpython/blob/aa1b8a168d8b8dc1dfc426364b7b664501302958/Lib/test/test_os.py ...
- How does Circus stack compare to a classical stack?
Frequently Asked Questions - Circus 0.15.0 documentation https://circus.readthedocs.io/en/latest/faq ...
- var、let、const之间的区别
var声明变量可以重复声明,而let不可以重复声明var是不受限于块级的,而let是受限于块级var会与window相映射(会挂一个属性),而let不与window相映射var可以在声明的上面访问变量 ...
- 【笔记】学习markdown
经过来自学长(姐?)的 嘲讽 善意提醒后,我才知道这个博客园好像 资瓷 markdown 于是我决定要认真学习markdown(绝不是因为洛谷题解又过不去了) 正常点: 由于没人教,我上网查了一下 一 ...