c++ STL里next_permutation()与prev_permutation()的基础用法

next_permutation()与prev_permutation()是全排列函数

next_permutation():将现有数组进行下一个排列

prev_permutation():将现有数组进行下一个排列

用法1:统计a数组后面的排列个数(不包括当前的排列)

    a[0]=1; 
    a[1]=2; 
    a[2]=3;
	while (next_permutation(a,a+n)) anss++;

用法2:输出a数组后面的所有排列方式(不包括当前的排列)

    a[0]=1; 
	a[1]=2; 
	a[2]=3;
	while (next_permutation(a,a+n)) 
	{
    
    
	    cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
	}

猜你喜欢

转载自blog.csdn.net/weixin_45485187/article/details/102508689