回复 20楼 有容就大
没必要的,而且答案应该有很多组
1 2 4 5 11
1 2 4 6 10
1 2 4 7 9
应该就这3组 等下去写个程序验证下。
[ 本帖最后由 有容就大 于 2012-2-29 13:21 编辑 ]
程序代码:#include <stdio.h>
#include <windows.h>
int main(void)
{
int a, b, c, d, e, count = 0;
for (a = 1; a <= 23; a++)
for (b = 1; b <= 23; b++)
for (c = 1; c <= 23; c++)
for (d = 1; d <= 23; d++)
for (e = 1; e <= 23; e++)
if (a + b + c + d + e == 23)
{
if (a != b && a != c && a != d && a != e)
if ( b != c && b != d && b != e)
if (c != d && c != e)
if (d != e)
if (a < b && b < c && c < d && d < e)
{
printf("%d\t%d\t%d\t%d\t%d\n", a, b, c, d, e);
count++;
}
}
printf("%d\n", count);
return 0;
}

程序代码:#include<stdio.h>
void sub_search(int id, int s, int a, int n, int r)
{
static int list[32];
int i, j;
if(n == 0)
{
for(i = 0; i < id; printf("%4d", list[i++]));
printf("\n");
return;
}
j = (1 << n - 1) - 1;
for(i = a + 1; i <= s + 1 && s + i <= r; i++)
if(s + i + j + (s + i) * j >= r)
sub_search(id + 1, s + i, list[id] = i, n - 1, r);
}
void search(int n, int r)
{
sub_search(0, 0, 0, n, r);
}
int main()
{
search(5, 23);
return 0;
}