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

暴力必备:next_permutation用法

时间:2018-11-04 11:07:01      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:com   比较   打表   http   常用   while   strong   常见   .com   

技术分享图片

next_permutation可以将一个序列变为第一个字典序大于她的序列,并且本身具有返回值,如果不存在字典序大于她的序列了就返回false

所以,标准用法:

    int len=3;
    do 
    {
        rep(i,1,len) cout<<num[i]<<" ";
        cout<<endl; 
    }
    while (next_permutation(num+1,num+1+len));

next_permutation函数还可以自定义比较函数:
技术分享图片

这样就是生成第一个比她字典序小的序列了。

next_permutation常用于计数类问题的暴力&&打表,以及常见的枚举,暴力,可以作为对拍程序来用,实现较为简单qwq

暴力必备:next_permutation用法

标签:com   比较   打表   http   常用   while   strong   常见   .com   

原文地址:https://www.cnblogs.com/bullshit/p/9903040.html

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