【全排列】next_permutation应用

在这里插入图片描述
在这里插入图片描述
这是一道结果填空题,所以
1.暴力12层循环,不要烦躁,冲就是了!奥利给!
2.终于用到next_permutation了
代码块:

int a[12]={1,2,3,4,5,6,7,8,9,10,11,12};
///////////A,b,c,d,E,F,g,H,i, J, K, L;
int main(){
	int ans=0;
	while(next_permutation(a,a+12)){
		if((a[1]+a[4])%2==0&&(a[2]+a[5]+a[6]+a[9]+a[10])%2==0
		&&(a[6]+a[9]+a[10])%2==0&&(a[3]+a[7]+a[8]+a[11])%2==0
		&&(a[8]+a[11])%2==0)
			ans++;
	}
	cout<<ans<<endl;

全排列函数在这个时候,用起来贼爽快。

发布了16 篇原创文章 · 获赞 0 · 访问量 110

猜你喜欢

转载自blog.csdn.net/weixin_44745441/article/details/104497707