码迷,mamicode.com
首页 > 其他好文 > 详细

SOS问题

时间:2020-03-28 01:17:25      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:any   search   cti   ble   numbers   cat   模板   src   chef   

SOS问题

模板

//iterative version
for(int mask = 0; mask < (1<<N); ++mask){
	dp[mask][-1] = A[mask];	
    //handle base case separately (leaf states)
	for(int i = 0;i < N; ++i){
		if(mask & (1<<i))
			dp[mask][i] = dp[mask][i-1] + dp[mask^(1<<i)][i-1];
		else
			dp[mask][i] = dp[mask][i-1];
	}
	F[mask] = dp[mask][N-1];
}

//memory optimized, super easy to code.
for(int i = 0; i<(1<<N); ++i)
	F[i] = A[i];
for(int i = 0;i < N; ++i) for(int mask = 0; mask < (1<<N); ++mask){
	if(mask & (1<<i))
		F[mask] += F[mask^(1<<i)];
}

技术图片

S(mask,i) 表示第0位到第i位不同的子集

时间复杂度\(O(N2^N)\)

tutorial

https://codeforces.com/blog/entry/45223

https://blog.csdn.net/weixin_38686780/article/details/100109753

例题

Practice Problems

I hope you enjoyed it. Following are some problems built on SOS.

EDIT: Practice problems are now arranged in almost increasing order of difficulty.

SOS问题

标签:any   search   cti   ble   numbers   cat   模板   src   chef   

原文地址:https://www.cnblogs.com/guaguastandup/p/12585207.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!