对于next_permutation函数是针对于排列组合问题的库函数,它的排序方式是按照字典的方式排列的·:

如以下代码对于next_permutation函数的初步解释:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
	//next_permutation()函数是基于algorithm头文件中的
	//如果本身还有排列组合那将返回true,否则返回false
	int a[5];
	for(int t=0;t<5;t++)
	{
		a[t]=t+1;
	 } 
	 //如果要从小到大排的的话,要进行排序
	 sort(a,a+5);//排序
	 int s=0;
	do
	 {  
	     s++;
	   for(int t=0;t<5;t++)
	   {
	   	cout<<" "<<a[t];
	   }
	   cout<<endl;
	  } while(next_permutation(a,a+5));
	 cout<<"sum = "<<s<<endl;
	return 0;
 } 

 

相关文章:

  • 2021-06-26
  • 2021-12-26
  • 2022-02-19
  • 2021-06-28
  • 2021-06-22
  • 2021-06-14
  • 2021-09-20
  • 2021-12-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2020-01-15
  • 2021-10-28
  • 2021-12-03
  • 2021-08-24
  • 2021-05-11
相关资源
相似解决方案