50分求一个组合的的的算法或程序~ 比如说用户输入S,K,S为数组中共有S个元素,从中抽出K个元素进行组合(不是排列)如1,2,3,4,和2,3,4,1是一样的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写段简单的递归:int S = 0;int K = 0;int* Result = NULL;int Number = 0;void Show(){ printf("%d:\t", ++Number); for (int i=0; i<K; i++) printf("%d\t", Result[i]); printf("\n");}void List(int Subscript, int LastValue){ if (Subscript == K) { Show(); return; } while (++LastValue <= S) { Result[Subscript] = LastValue; List(Subscript+1, LastValue); }}void main(){ printf("S="); scanf("%d", &S); printf("K="); scanf("%d", &K); if (K > 0 && S >= K) { Result = new int[S]; List(0, 0); delete Result; }} 关于获取图片像素坐标 在ftp服务器端控制客户端上传文件 从 CDialog 继承的类,创建对象,句柄老是无效………… 能否用Win32的静态库 生成另外一个静态库 做RTP传输,总是返回Can't create a socket,怎么办? Unicode and ANSI文本文件的读取 解释下面代码 初学C++,请各位前辈推荐几本好书。。。。。在线等待。。。。 誰知道gerber及dxf文件格式 如何得到IE當前的字符集設置?? 《com 原理与应用》第四章·进程外组件例子程序 为什么我总是必须事先手动运行 Dictionary.exe 才能成功? 我的ActiveX控件
int S = 0;
int K = 0;
int* Result = NULL;
int Number = 0;void Show()
{
printf("%d:\t", ++Number);
for (int i=0; i<K; i++)
printf("%d\t", Result[i]);
printf("\n");
}void List(int Subscript, int LastValue)
{
if (Subscript == K)
{
Show();
return;
}
while (++LastValue <= S)
{
Result[Subscript] = LastValue;
List(Subscript+1, LastValue);
}
}void main()
{
printf("S=");
scanf("%d", &S);
printf("K=");
scanf("%d", &K);
if (K > 0 && S >= K)
{
Result = new int[S];
List(0, 0);
delete Result;
}
}