当前位置:网站首页>Niuke challenge 53:c. strange magic array
Niuke challenge 53:c. strange magic array
2022-06-26 13:57:00 【__ LazyCat__】
link : Strange magic array (nowcoder.com)
The question : Given n n n Points and m m m side , Find the number of independent subsets of all sets , namely ∑ S ⊂ T [ S by single state Set ] \sum_{S \subset T}[S Is an independent set ] ∑S⊂T[S by single state Set ], Then hash the number of independent sets of all sets to find the final answer , namely a n s = ∑ T ⊂ N 23 3 ∑ i ⊂ T 2 i ∗ ∑ S ⊂ T [ S by single state Set ] ans=\sum_{T \subset N} 233^{\sum_{i \subset T} 2^i}*\sum_{S \subset T}[S Is an independent set ] ans=∑T⊂N233∑i⊂T2i∗∑S⊂T[S by single state Set ].
( Define independent sets S S S by S S S All points in are isolated points , Two are not connected .)
Answer key : According to the title, it is obviously necessary to enumerate [ 0 , 2 n − 1 ] [0,2^n-1] [0,2n−1] All sets of , Then consider how to inherit the answer from the previously calculated set . It can be found that for a set T T T, T T T It can be composed of two sets , The most convenient one is T T T The lowest bit in binary system is a set with only one element , The remaining bits form another set ( It is not allowed to enumerate like ordinary pressure n n n Positions make up n n n Methods ( The set has no order ), Just take it here once , Otherwise it will overlap ).
Computing sets y y y It can be used l o w b i t \text lowbit lowbit The function takes the second power of the lowest order directly , Then subtract from the current set y y y You can get x x x aggregate , about y y y And x x x The combination of sets , Find out y y y Corresponding element position p [ y ] p[y] p[y], take x x x Also the position of the element m p mp mp value ( An element that has an edge with this element ) And , Then seek x x x And the XOR of the result can be obtained x x x Set does not match y y y Conflicting point sets , The final answer is f [ i ] = f [ y ] + f [ x ] + f [ x ⊕ ( x & m p [ p [ y ] ] ) ] f[i]=f[y]+f[x]+f[x \oplus (x\&mp[p[y]])] f[i]=f[y]+f[x]+f[x⊕(x&mp[p[y]])]
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=(1<<26)+5;
const int mod=1e9+7;
int f[maxn],p[maxn],mp[30],n,m,x,y;
ll ans;
inline int lowbit(int x)
{
return x&(-x);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++)p[1<<i]=i;
for(int i=1;i<=m;i++)
{
cin>>x>>y;
mp[x]|=1<<y;
mp[y]|=1<<x;
}
for(int i=1;i<1<<n;i++)
{
int y=lowbit(i),x=i-y,z=x^(x&mp[p[y]]);
if(i==y)f[i]=1;
else f[i]=(1ll*f[y]+1ll*f[x]+1ll*f[z])%mod;
}
ll up=1;
for(int i=0;i<1<<n;i++)
{
ans=(ans+up*(1ll*f[i]+1)%mod)%mod; up=up*233%mod;
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- Exercise set 1
- HW蓝队溯源流程详细整理
- [proteus simulation] Arduino uno key start / stop + PWM speed control DC motor speed
- A collection of common tools for making we media videos
- Zero basics of C language lesson 7: break & continue
- Detailed sorting of HW blue team traceability process
- ICML 2022 | limo: a new method for rapid generation of targeted molecules
- Jenkins build prompt error: eacces: permission denied
- Half search, character array definition, character array uses D11
- PHP非对称加密算法(RSA)加密机制设计
猜你喜欢

Common operation and Principle Exploration of stream

windows版MySQL软件的安装与卸载

Create your own cross domain proxy server

Embedded virlog code running process

7.consul service registration and discovery

ICML 2022 | LIMO: 一种快速生成靶向分子的新方法

Echart stack histogram: add white spacing effect setting between color blocks

Detailed sorting of HW blue team traceability process

Design of simple digital circuit traffic light

awk工具
随机推荐
泰山OFFICE技术讲座:使用字体粗体的四种情形
GC is not used in D
HW蓝队溯源流程详细整理
CVPR 2022文档图像分析与识别相关论文26篇汇集简介
Cloudcompare - Poisson reconstruction
Bigint: handles large numbers (integers of any length)
Sed editor
Aesthetic experience (episode 238) Luo Guozheng
7-2 picking peanuts
2021-10-18 character array
Memory considerations under bug memory management
MediaPipe手势(Hands)
Nlp-d60-nlp competition D29
On insect classes and objects
遍历指定目录获取当前目录下指定后缀(如txt和ini)的文件名
同花顺股票开户选哪个证券公司是比较好,比较安全的
There are many contents in the widget, so it is a good scheme to support scrolling
Introduction to 26 papers related to CVPR 2022 document image analysis and recognition
Pytorch based generation countermeasure Network Practice (7) -- using pytorch to build SGAN (semi supervised GaN) to generate handwritten digits and classify them
去某东面试遇到并发编程问题:如何安全地中断一个正在运行的线程