當前位置:首頁 » 操作系統 » M合成演算法

M合成演算法

發布時間: 2025-02-08 11:26:22

❶ 組合演算法:從m個數中選n個數的所有組合

#include <iostream.h>

int combine(int a[], int n, int m)
{
m = m > n ? n : m;

int* order = new int[m+1];
for(int i=0; i<=m; i++)
order[i] = i-1;

int count = 0;
int k = m;
bool flag = true;
while(order[0] == -1)
{
if(flag)
{
for(i=1; i<=m; i++)
cout << a[order[i]] << " ";
cout << endl;
count++;
flag = false;
}

order[k]++;
if(order[k] == n)
{
order[k--] = 0;
continue;
}

if(k < m)
{
order[++k] = order[k-1];
continue;
}

if(k == m)
flag = true;
}

delete[] order;
return count;
}

int main()
{
const int M = 4;
const int N = 3;
int a[M];
int b[N];
for(int i=0;i<M;i++)
a[i] = i+1;

combine(a,M,N);

return 0;
}

熱點內容
抖音社區源碼 發布:2025-09-16 16:12:48 瀏覽:133
酷派內置存儲空間不足 發布:2025-09-16 15:50:44 瀏覽:399
php設置編碼格式 發布:2025-09-16 15:20:04 瀏覽:612
php取兩位小數點 發布:2025-09-16 15:12:40 瀏覽:315
加密塊流加密 發布:2025-09-16 15:07:36 瀏覽:701
sqldeveloper導出表 發布:2025-09-16 15:07:33 瀏覽:366
xbox360ftp 發布:2025-09-16 14:45:34 瀏覽:852
火車站附近wifi密碼是多少 發布:2025-09-16 14:45:30 瀏覽:195
國家標准加密 發布:2025-09-16 14:45:27 瀏覽:954
php集成支付寶 發布:2025-09-16 14:05:28 瀏覽:723