當前位置:首頁 » 操作系統 » 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;
}

熱點內容
php辦公系統 發布:2025-07-19 03:06:35 瀏覽:896
奧德賽買什麼配置出去改裝 發布:2025-07-19 02:53:18 瀏覽:38
請與網路管理員聯系請求訪問許可權 發布:2025-07-19 02:37:34 瀏覽:187
ipad上b站緩存視頻怎麼下載 發布:2025-07-19 02:32:17 瀏覽:842
phpcgi與phpfpm 發布:2025-07-19 02:05:19 瀏覽:525
捷達方向機安全登錄密碼是多少 發布:2025-07-19 00:57:37 瀏覽:690
夜魔迅雷下載ftp 發布:2025-07-19 00:39:29 瀏覽:97
增值稅票安全接入伺服器地址 發布:2025-07-19 00:20:45 瀏覽:484
solidworkspcb伺服器地址 發布:2025-07-18 22:50:35 瀏覽:820
怎麼在堆疊交換機里配置vlan 發布:2025-07-18 22:42:35 瀏覽:628