当前位置:网站首页>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;
}
边栏推荐
- MongoDB系列之Window环境部署配置
- GO语言-管道channel
- 创建一个自己的跨域代理服务器
- Detailed sorting of HW blue team traceability process
- Is expression of D
- Ubuntu installation and configuration PostgreSQL (18.04)
- Generation and rendering of VTK cylinder
- Firewall introduction
- Es sauvegarde et restauration des données par instantané
- There are many contents in the widget, so it is a good scheme to support scrolling
猜你喜欢

爱可可AI前沿推介(6.26)

CloudCompare——泊松重建

Nexys A7开发板资源使用技巧

Learn how to develop owl components by hand (7): practical use of owl projects

Gurivat sprint Harbour Exchange listed: created “multiple first”, received 900 million yuan Investment from IDG capital

Reprint - easy to use wechat applet UI component library

ES基于Snapshot(快照)的数据备份和还原

Free machine learning dataset website (6300+ dataset)

windows版MySQL软件的安装与卸载

Thinking caused by the error < note: candidate expectations 1 argument, 0 provided >
随机推荐
Is expression of D
计算两点之间的距离(二维、三维)
Mongodb series window environment deployment configuration
Traverse the specified directory to obtain the file name with the specified suffix (such as txt and INI) under the current directory
HW蓝队溯源流程详细整理
imagecopymerge
Common operation and Principle Exploration of stream
MediaPipe手势(Hands)
Taishan Office Technology Lecture: four cases of using bold font
Half search, character array definition, character array uses D11
Input text to automatically generate images. It's fun!
【系统分析师之路】第十五章 复盘数据库系统(数据库案例分析)
Is it safe to open a securities account? Is there any danger
MongoDB系列之适用场景和不适用场景
Variable declaration of typescript
Stack, LIFO
使用 Performance 看看浏览器在做什么
A few lines of code can realize complex excel import and export. This tool class is really powerful!
虫子 STL string 下 练习题
33、使用RGBD相机进行目标检测和深度信息输出