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 ...
随机推荐
- 命名秘籍周获近五千星——GitHub 热点速览 v.21.04
作者:HelloGitHub-小鱼干 命名一直是编程界的难点,这次 naming-cheatsheet 就能帮上你的忙.按照它的 SID(Short..Intuitive.Descriptive)原则 ...
- Scrapy———反爬蟲的一些基本應對方法
1. IP地址驗證 背景:有些網站會使用IP地址驗證進行反爬蟲處理,檢查客戶端的IP地址,若同一個IP地址頻繁訪問,則會判斷該客戶端是爬蟲程序. 解決方案: 1. 讓Scrapy不斷隨機更換代理服務器 ...
- 解决Linux下mysql区分大小写的问题
1.查看lower_case_table_names的值,0代表区分大小写,1代表不区分大小写. 通过命令:SHOW VARIABLES LIKE 'lower%'; 1. 解决方法 以root用户登 ...
- CentOS7.9静默安装Oracle19C软件
CentOS7.9静默安装Oracle19C软件 Oracle发布了支持的版本.可以看到了Oracle11gR2和Oracle12C.一直到2022年就不支持patch和服务.(感慨Oracle 11 ...
- python中贪婪与非贪婪
Python里数量词默认是贪婪的(在少数语言里也可能是默认非贪婪),总是尝试匹配尽可能多的字符: 非贪婪则相反,总是尝试匹配尽可能少的字符. 在"*","?", ...
- 洛谷P1858
\({\mathcal{For}}\) \({\mathcal{we}\ }\)\({\mathcal{live}\ }\)\({\mathcal{by}\ }\)\({\mathcal{faith} ...
- day133:2RenMJ:TypeScript的变量&函数&类&接口
目录 1.变量 2.函数 3.类 4.接口 1.变量 1.变量的声明 // 1.即指定数据类型 也指定值 var 变量名:类型 = 值; eg:var username:string = " ...
- tcpdump抓包及tshark解包方法介绍
tshark是wireshark的命令行工具,通过shell命令抓取.解析报文.tcpdump是Linux系统下的抓包工具.wireshark和tcpdump都共同使用 libpcap作为其底层抓包的 ...
- python -m http.server 搭建一个简易web下载服务器
在打vulnhub靶场的时候遇到的一个问题 目录 一.进到需要发送的安装包目录 二.开启http服务 三.访问服务器 一.进到需要发送的安装包目录 比如设置一个专门发送,传输的文件的文件夹,cmd命令 ...
- K8s (常用命令)
查看集群信息: [root@kubernetes-master pods]# kubectl cluster-infoKubernetes master is running at http://lo ...