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 ...
随机推荐
- 【MYSQL】DDL语句
介绍:DDL语句,即数据定义语句,定义了不同的数据段,数据库表.表.列.索引等数据库对象:例如,create.drop.alter 适用对象:一般是由数据库管理员DBA使用 1.连接数据库 mysql ...
- 接收的参数为日期类型、controller控制层进行数据保存、进行重定向跳转
目录 1.接收的参数为日期类型 2.controller控制层进行数据保存 3.controller层如何进行重定向跳转(因为默认是请求转发) 4.静态资源的映射 1.接收的参数为日期类型 WEB-I ...
- 翻译 - ASP.NET Core 基本知识 - 通用主机 (Generic Host)
翻译自 https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-5.0 ...
- Flask扩展点总结(信号)
信号(源码) 信号,是在flask框架中为我们预留的钩子,让我们可以进行一些自定义操作. pip3 install blinker 根据flask项目的请求流程来进行设置扩展点 1.中间件 from ...
- 微信小程序代码上传,审核发布小程序
1.打开微信开发者工具 管理员扫码 -> 填写好小程序的项目目录.AppID(必须是客户已注册好的AppID).项目名称 2.在app.js中修改id(客户登录后台管理系统的id),app.js ...
- 浅析Redis与IO多路复用器原理
为什么Redis使用多路复用I/O Redis 是跑在单线程中的,所有的操作都是按照顺序线性执行的,但是由于读写操作等待用户输入或输出都是阻塞的,所以 I/O 操作在一般情况下往往不能直接返回,这会导 ...
- Go Concurrency Patterns: Context At Google, we require that Go programmers pass a Context parameter as the first argument to every function on the call path between incoming and outgoing requests.
小结: 1. Background is the root of any Context tree; it is never canceled: 2. https://blog.golang. ...
- 前端调用微信小程序的支付流程
目录 1,前言 2,流程 3,参数说明 4,具体代码 1,前言 分享一个完整的微信小程序支付流程中,前端要做的模块. 2,流程 在调用wx.requestPayment之前,需要准备一些参数,流程如下 ...
- MySQL安装+初始化操作(1)
先去官网下载自己适合的版本,在这里我选择下载Windows 64位版本的,这是下载地址. 1.下载MySQL,步骤①==>步骤② 2.下载后,解压到除系统盘(C盘)之外的其他盘中 3.解压后在b ...
- hive-2.2.0 伪分布式环境搭建
一,实验环境: 1, ubuntu server 16.04 2, jdk,1.8 3, hadoop 2.7.4 伪分布式环境或者集群模式 4, apache-hive-2.2.0-bin.tar. ...