當前位置:首頁 » 操作系統 » 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-02-08 14:09:25 瀏覽:435
python過濾器 發布:2025-02-08 14:05:06 瀏覽:615
火山幣演算法 發布:2025-02-08 14:04:49 瀏覽:668
jffs2解壓 發布:2025-02-08 13:55:15 瀏覽:388
如何向伺服器發送大數據包 發布:2025-02-08 13:55:12 瀏覽:662
伺服器pop地址是什麼 發布:2025-02-08 13:39:21 瀏覽:386
網站訪問計數器 發布:2025-02-08 13:32:07 瀏覽:6
釣魚的腥怎麼配置 發布:2025-02-08 13:22:57 瀏覽:754
php數組的引用 發布:2025-02-08 13:22:54 瀏覽:94
致遠a6伺服器地址在哪裡看 發布:2025-02-08 13:22:06 瀏覽:132