当前位置:网站首页>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;
}
边栏推荐
- [hcsd application development training camp] one line of code second cloud evaluation article - experience from the experiment process
- 12 SQL optimization schemes summarized by old drivers (very practical)
- [MySQL from introduction to mastery] [advanced part] (II) representation of MySQL directory structure and tables in the file system
- Use of wangeditor rich text editor
- 7-3 minimum toll
- Es snapshot based data backup and restore
- CloudCompare——泊松重建
- Variable declaration of typescript
- 去某东面试遇到并发编程问题:如何安全地中断一个正在运行的线程
- D中不用GC
猜你喜欢
ICML 2022 | LIMO: 一种快速生成靶向分子的新方法
ES中索引别名(alias)的到底有什么用
古瑞瓦特沖刺港交所上市:創下“多個第一”,獲IDG資本9億元投資
微信小程序注册指引
Wechat applet magic bug - choose to replace the token instead of clearing the token, wx Getstoragesync will take the old token value instead of the new token value
Guruiwat rushed to the Hong Kong stock exchange for listing: set "multiple firsts" and obtained an investment of 900million yuan from IDG capital
33、使用RGBD相机进行目标检测和深度信息输出
Wechat applet -picker component is repackaged and the disabled attribute is added -- above
Pytorch based generation countermeasure Network Practice (7) -- using pytorch to build SGAN (semi supervised GaN) to generate handwritten digits and classify them
Embedded virlog code running process
随机推荐
A collection of common tools for making we media videos
Thinking caused by the error < note: candidate expectations 1 argument, 0 provided >
[MySQL from introduction to mastery] [advanced part] (II) representation of MySQL directory structure and tables in the file system
Stream常用操作以及原理探索
D check type is pointer
7-2 a Fu the thief
es常用语法一
A primary multithreaded server model
【HCSD应用开发实训营】一行代码秒上云评测文章—实验过程心得
In insect classes and objects
Input text to automatically generate images. It's fun!
Sed editor
Generate JDE dot train
DataGrip配置的连接迁移
33. Use rgbd camera for target detection and depth information output
虫子 类和对象 中
免费的机器学习数据集网站(6300+数据集)
古瑞瓦特沖刺港交所上市:創下“多個第一”,獲IDG資本9億元投資
Wechat applet -picker component is repackaged and the disabled attribute is added -- above
Connection migration for DataGrid configuration