当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Mediapipe gestures (hands)

李航老师新作《机器学习方法》上市了!附购买链接

What is the use of index aliases in ES

8.Ribbon负载均衡服务调用

Use performance to see what the browser is doing

Common operation and Principle Exploration of stream

去某东面试遇到并发编程问题:如何安全地中断一个正在运行的线程

Ring queue PHP

hands-on-data-analysis 第三单元 模型搭建和评估

Gurivat sprint Harbour Exchange listed: created “multiple first”, received 900 million yuan Investment from IDG capital
随机推荐
mysql配置提高数据插入效率
Select tag - uses the default text as a placeholder prompt but is not considered a valid value
7-2 picking peanuts
免费的机器学习数据集网站(6300+数据集)
Wechat applet SetData dynamic variable value sorting
Embedded virlog code running process
网络远程访问的方式使用树莓派
A few lines of code can realize complex excel import and export. This tool class is really powerful!
Traverse the specified directory to obtain the file name with the specified suffix (such as txt and INI) under the current directory
Aesthetic experience (episode 238) Luo Guozheng
A primary multithreaded server model
On insect classes and objects
CVPR 2022文档图像分析与识别相关论文26篇汇集简介
Global variable vs local variable
In insect classes and objects
Input text to automatically generate images. It's fun!
d检查类型是指针
PHP非对称加密算法(RSA)加密机制设计
MongoDB系列之适用场景和不适用场景
MediaPipe手势(Hands)