当前位置:网站首页>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;
}
边栏推荐
- Solutions to the failure of last child and first child styles of wechat applet
- Introduction to 26 papers related to CVPR 2022 document image analysis and recognition
- 三维向量的夹角
- Connection migration for DataGrid configuration
- Network remote access using raspberry pie
- imagecopymerge
- The most critical elements of team management
- Is it safe to open a securities account? Is there any danger
- Included angle of 3D vector
- Generation and rendering of VTK cylinder
猜你喜欢

Lamp compilation and installation

Nexys A7开发板资源使用技巧

Wechat applet -picker component is repackaged and the disabled attribute is added -- below

7.consul service registration and discovery

古瑞瓦特冲刺港交所上市:创下“多个第一”,获IDG资本9亿元投资

12 SQL optimization schemes summarized by old drivers (very practical)

Variable declaration of typescript

Exercise set 1

Free machine learning dataset website (6300+ dataset)

2021-10-09
随机推荐
遍历指定目录获取当前目录下指定后缀(如txt和ini)的文件名
【系统分析师之路】第十五章 复盘数据库系统(数据库案例分析)
Detailed sorting of HW blue team traceability process
Introduction to 26 papers related to CVPR 2022 document image analysis and recognition
In insect classes and objects
[path of system analyst] Chapter 15 double disk database system (database case analysis)
同花顺股票开户选哪个证券公司是比较好,比较安全的
去某东面试遇到并发编程问题:如何安全地中断一个正在运行的线程
Es6: iterator
A few lines of code can realize complex excel import and export. This tool class is really powerful!
d的is表达式
Range of types
windows版MySQL软件的安装与卸载
awk工具
程序员必备,一款让你提高工作效率N倍的神器uTools
Wechat applet -picker component is repackaged and the disabled attribute is added -- below
MongoDB系列之Window环境部署配置
Wechat applet SetData dynamic variable value sorting
character constants
免费的机器学习数据集网站(6300+数据集)