这个程序 Dos 环境中 TC 怎么写啊?

a00b00 2001-10-21 05:02:08
int s[10]={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };


程序是要将 1-10 中的所有数字按每行不出现重复数字的原则以 5 个数字组合为一行,最多能组合成几行?


程序是这样循环打印的吗?

000 1,2,3,4,5
001 1,3,4,5,6
002 1,4,5,6,7
003 ......

... 1,2,4,5,6
... 1,2,5,6,7
... 1,2,6,7,8
n-1 ......

小弟水平极菜,请兄弟们帮忙救命,谢谢!
...全文
111 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
a00b00 2001-10-23
  • 打赏
  • 举报
回复
给分了
hsq 2001-10-23
  • 打赏
  • 举报
回复
不好意思。我家上午有事。抱歉
#include "stdio.h"
#include "stdlib.h"
int times=0;
int Total_Num;
void OutTeam(Buffer,Num)
int *Buffer;
int Num;
{int i;
for (i=0;i<Num;i++)
printf("%3d",Buffer[i]);
printf("\n");
times++;
}
void MovePosition(Position,DesNum,Buffer)
int Position,DesNum;
int *Buffer;
{Buffer[Position]=DesNum;
OutTeam(Buffer,Position+1);
}
void SubAssign(Buffer,Position,Orig_Value,DesValue,Standard)
int *Buffer;
int Position,Orig_Value,DesValue,Standard;
{
if ((Position==Standard-1)&&(Orig_Value<=DesValue))
{MovePosition(Position,Orig_Value,Buffer);
SubAssign(Buffer,Position,++Orig_Value,DesValue,Standard);
}
else
{
while(Orig_Value<=DesValue)
{Buffer[Position]=Orig_Value;
SubAssign(Buffer,Position+1,Buffer[Position]+1,Total_Num-(Standard-1-(Position+1)),Standard);
Orig_Value++;
}
}
}
void main(void)
{int Standard;
int *Buffer;
int i,OrigPosition=0;
fprintf(stderr,"\nHow many numbers do you want to assign\nTotal_Num=");
scanf("%d",&Total_Num);
fprintf(stderr,"\nWhich numbers do you want to assign in a team\nStandard=");
scanf("%d",&Standard);
printf("\n");
Buffer=calloc(Standard,sizeof(int));
for (i=0;i<Standard;i++)
Buffer[i]=i+1;
SubAssign(Buffer,OrigPosition,Buffer[OrigPosition],Total_Num-(Standard-1-OrigPosition),Standard);
free(Buffer);
fprintf(stderr,"\ttimes=%d",times);
}
修过了
a00b00 2001-10-22
  • 打赏
  • 举报
回复
7rainbow(jiejie) 老兄啊,问题是我现在不懂要怎么写这个算法
hsq 2001-10-22
  • 打赏
  • 举报
回复
在等一下。我已经怎么编了
a00b00 2001-10-22
  • 打赏
  • 举报
回复
晕!看不懂!

老大能不能麻烦您写几句较详细的语句啊,谢谢!
7rainbow 2001-10-22
  • 打赏
  • 举报
回复
用回逆法是可以的。
a00b00 2001-10-22
  • 打赏
  • 举报
回复
sq() 非常感谢你

在 TC2.0 编译运行后是这样
**************************************************
C:\TC\C>22
How many numbers do you want to assign
Total_Num=5

Which numbers do you want to assign in a team
Standard=3

1 2 3
1 2 4
1 2 5--------1
1 3 5
2 3 5
1 3 4
1 2 5--------2
1 3 5
2 3 5
2 3 4
1 2 5--------3
1 3 5
2 3 5
times=13
C:\TC\C>

**************************************************
好象有重复啊,我按5个数字,每行3个输出
1 2 5
1 3 5
2 3 5
出现了3次

程序要求不能重复,也不能缺少
000 1,2,3,4,5
001 1,3,4,5,6
002 1,4,5,6,7
003 ......
... 2,3,4,5,6
... 2,4,5,6,7
... 2,5,6,7,8
......
a00b00 2001-10-22
  • 打赏
  • 举报
回复
yug(寒鹤) axial() 

感谢两位大哥的提示!
a00b00 2001-10-22
  • 打赏
  • 举报
回复
up
a00b00 2001-10-22
  • 打赏
  • 举报
回复
哈哈哈

你答对了!

我只有初中文凭,而且实际水平可能只有初一吧
PP_Sky 2001-10-22
  • 打赏
  • 举报
回复
你是读初中的吗?好像高中的数学就有这样的题啊?
hsq 2001-10-22
  • 打赏
  • 举报
回复
#include "stdio.h"
#include "stdlib.h"
int times=0;
void CopyOne(Buffer,Acopy,Num)
int *Buffer,*Acopy;
int Num;
{int i;
for(i=0;i<Num;i++)
Acopy[i]=Buffer[i];
}
void OutTeam(Buffer,Num)
int *Buffer;
int Num;
{int i;
for (i=0;i<Num;i++)
printf("%3d",Buffer[i]);
printf("\n");
times++;
}
void MovePosition(Start,Counts,DesNum,Buffer,Standard)
int Start,Counts,DesNum,Standard;
int *Buffer;
{int i,j;
if (Start==Standard-1)
Buffer[Start]=DesNum;
else
{for(i=Start,j=0;j<Counts;j++,i++)
Buffer[i]=Buffer[i+1];
Buffer[Standard-1]=DesNum;
}
OutTeam(Buffer,Standard);
}
void Assign(Buffer,Standard,DesNum,TotalNum,Acopy)
int *Buffer,*Acopy;
int Standard,DesNum,TotalNum;
{int i;
if (DesNum<=TotalNum)
for (i=0;i<Standard;i++)
{MovePosition(Standard-1-i,i,DesNum,Buffer,Standard);
CopyOne(Acopy,Buffer,Standard);
if(DesNum+1<=TotalNum)
Assign(Buffer,Standard,DesNum+1,TotalNum,Acopy);
}


}
void main(void)
{int Total_Num,Standard;
int *Buffer,*Acopy;
int i;
fprintf(stderr,"How many numbers do you want to assign\nTotal_Num=");
scanf("%d",&Total_Num);
fprintf(stderr,"\nWhich numbers do you want to assign in a team\nStandard=");
scanf("%d",&Standard);
printf("\n");
Buffer=calloc(Standard,sizeof(int));
Acopy=calloc(Standard,sizeof(int));
for (i=0;i<Standard;i++)
Buffer[i]=i+1;
CopyOne(Buffer,Acopy,Standard);
OutTeam(Buffer,Standard);
Assign(Buffer,Standard,Standard+1,Total_Num,Acopy);
free(Buffer);
free(Acopy);
fprintf(stderr,"\ttimes=%d",times);
} 我已经调过。完全OK.give me the scores
axial 2001-10-21
  • 打赏
  • 举报
回复
这就清楚了:
1,有序的情况:
如{1,2,3,4,5}和{1,2,3,5,4}算两种情况
P(10,5)=10!/(10-5)!=10*9*8*7*6=....
是这样的,每行是五个,就要从10个数中先后选出5个数,
第一个有10种选法,即从10个不同的数中选一个有10种选法,
第二个有9种(第一个选过的不能重复),
第3个有8种......
而且能保证这样选出来的没有重复。
2,无序的情况:
如:{1,2,3,4,5}和{1,2,3,5,4}算一种情况。
C(10,5)=10!/(5!*(10-5)!)=(10*9*8*7*6)/(5*4*3*2*1)=......
因为选出来的5个数有5!=5*4*3*2*1种组合,又因为是无序,所以要在有序的基础上除以5!。
如果再不明白,参看集合论中的排列组合,这是最基本的概念。
yug 2001-10-21
  • 打赏
  • 举报
回复
P(10,5) 或者 C(10,5)

33,010

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧