1. 程式人生 > >暴力必備:next_permutation用法

暴力必備:next_permutation用法

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