[問題] 組合Cm取n的遞迴
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
stdio
stdlib
問題(Question):
無法了解網路上的某篇程式
餵入的資料(Input):
C 5 取 3
預期的正確結果(Expected Output):
無
錯誤結果(Wrong Output):
無
程式碼(Code):(請善用置底文網頁, 記得排版)
#include<stdio.h>
#include<stdlib.h>
int way[1001]= {0};
int n,m;
void make (int now,int a,int n,int m)
{
int b=a,c;
if(now==m+1)
{
for(c=1; c<=m; c++)printf("%d ",way[c]);
printf("\n");
return;
}
else
for(b=a; b<=n; b++)
{
way[now]=b;
make(now+1,b+1,n,m);
}
}
main()
{
while(scanf("%d %d",&n,&m)==2)
make(1,1,n,m);
return 0;
}
補充說明(Supplement):
已經想破腦袋了
甚至使用暴力法把程式怎麼跑的一一列出
結果就是看到函式進入堆疊以後不斷的recurtion就排出答案
最弄不懂的地方是make前面的兩個參數到底是怎麼做到組合的
希望有人可以幫我解答一下
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.68.131
→
05/03 22:50, , 1F
05/03 22:50, 1F
→
05/03 22:51, , 2F
05/03 22:51, 2F
推
05/03 23:40, , 3F
05/03 23:40, 3F
→
05/04 04:26, , 4F
05/04 04:26, 4F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章