# 請問一個關於數學的全排列組合的寫法

## 請問一個關於數學的全排列組合的寫法

##### 代碼:
```clear all;clc;close all; job_num = 6 n_1 = prod(1:job_num);   % 1~job_num的累乘積值 row = n_1; col = job_num; allorder_K = zeros(1:job_num-1); cnt = 0; period = n_1/1000; total = 0; for allorder_m = 1:n_1     allorder_flag=zeros(1,job_num);     allorder_P = zeros(1,job_num);     for allorder_i = 1:job_num-1         position = job_num-allorder_K(allorder_i);         allorder_j = job_num;         while(allorder_j >= position)             if(allorder_flag(allorder_j)==1)                 position = position-1;             end             allorder_j =allorder_j-1;         end         allorder_P(position)=job_num+1-allorder_i;         allorder_flag(position)=1;     end     for allorder_i = 1:job_num         if (allorder_flag(allorder_i)==0)             allorder_P(allorder_i)=1;             break;         end     end     %%%%%%%%以下更新k     for allorder_i = 1:job_num-1         allorder_K(job_num-allorder_i)=mod(allorder_K(job_num-allorder_i)+1,allorder_i+1);         if (allorder_K(job_num-allorder_i)~=0)             break;         end     end     %%%下面，可以引用allorder_P進行相關處理         cnt = cnt+1         allorder_P %-------------------------------------------------------------------------- % for m =1:row %     sort_ind = matrix(m, :);           sort_ind = allorder_P; %--------------------------------------------------------------------------          end ```

TOP

﻿