• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
nannandbk
博客园    首页    新随笔    联系   管理    订阅  订阅
next_permutation 函数

next_permutation 函数

next_permutation是全排列函数。

一、基本用法

int a[];
do{
    
}while(next_permutation(a,a+n));

二、例题

[P1088 [NOIP2004 普及组] 火星人]([P1088 NOIP2004 普及组] 火星人 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn))

#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[10010];
int main()
{
	cin>>n>>m;
	for(int i = 1;i<=n;i++)cin>>a[i];
	
	for(int i = 1;i<=m;i++)
	{
		next_permutation(a+1,a+1+n);
	}
	for(int i = 1;i<=n;i++)cout<<a[i]<<" ";

	return 0;
}
posted on 2023-07-09 12:58  nannandbk  阅读(272)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3