#4507. Independent set 1

题目描述

求无向图的所有导出子图的最大独立集大小的和.

导出子图:若图 G ′ G' G 是图 G G G 的导出子图,则

  • G ′ G' G 的点集是图 G G G 的点集的子集;

  • G ′ G' G 中存在边 ( a , b ) (a,b) (a,b),当且仅当点 a a a, b b b G ′ G' G 中,且 G G G 中存在边 ( a , b ) (a,b) (a,b).

独立集:图中两两互不相邻的顶点构成的集合.

最大独立集:点数最大的独立集.

数据范围

100 % 100\% 100% 的数据, 2 ≤ n ≤ 26 2\le n\le 26 2n26, m ≤ n × ( n − 1 ) 2 m\le \frac{n\times (n-1)}{2} m2n×(n1).

题解

考虑新加入一个节点对原来的图的影响

所以设 f s f_s fs 表示选择了 s s s 状态的点的最大独立集点数

假设新加入一个节点 i i i ,那对于原来的图的状态 j ∈ [ 0 , 2 i − 1 ] j∈[0,2^i-1] j[0,2i1] ,可以列出 d p dp dp式子:

f j ∣ ( 2 i ) = m a x ( f j , f j & ( ( 2 n − 1 ) ⊕ a i ) + 1 ) f_{j|(2^i)}=max(f_j,f_{j \& ((2^n-1) \oplus a_i)}+1) fj(2i)=max(fj,fj&((2n1)ai)+1)

其中 a i a_i ai 为与 i i i 相连的点的状态

代码

#include <bits/stdc++.h>
using namespace std;
int n,m,a[27],f[1<<26],ans;
int main(){
	scanf("%d%d",&n,&m);
	for (int u,v,i=0;i<m;i++)
		scanf("%d%d",&u,&v),
		a[v]|=(1<<u),a[u]|=(1<<v);
	for (int s=1,i=0;i<n;i++,s<<=1)
		for (int j=0;j<s;j++)
			f[j|s]=max(f[j],f[j&(~a[i])]+1);
	for (int i=(1<<n)-1;~i;i--) ans+=f[i];
	return printf("%d\n",ans),0;
}
Sure! To create a multivariate model using the steps you mentioned, you can follow the code snippet below: ```python from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression from sklearn.metrics import accuracy_score # Step 1: Create a linear model using the independent variable with the highest correlation # Assuming you have a pandas DataFrame called 'data' with independent variables 'X1', 'X2', 'X3', ..., and dependent variable 'y' X = data[['X1']] # Select the independent variable with the highest correlation y = data['y'] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0) model = LinearRegression() model.fit(X_train, y_train) train_accuracy = model.score(X_train, y_train) test_accuracy = model.score(X_test, y_test) print("Model 1 - Independent Variable: X1") print("Training Accuracy:", train_accuracy) print("Testing Accuracy:", test_accuracy) # Step 2: Add the independent variable with the next highest correlation and create a new linear model X = data[['X1', 'X2']] # Add the independent variable with the next highest correlation # Repeat the train-test split and model fitting process # Step 3: Repeat Step 2 for additional independent variables, evaluating accuracy each time ``` You can repeat Step 2 and Step 3 by adding more independent variables to `X` and fitting the linear regression model. Remember to perform the train-test split for each model and set `random_state` to 0 to ensure consistent results.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值