/*问题::把10个苹果分成三堆,每堆至少1个,应有多少种分法*/
#include <stdio.h>
#include <conio.h>
#define N 10      /*可以扩展到任意自然数>=3*/
void main()
{/*避免重复 要求第一堆总是少于等于第二堆,第二堆总是少于等于第三堆*/
  int i=1,j=1,k=1,cout=0;
  for(i=1;i<=N/2;i++)
   for(j=i,k=N-i-j;j<N-1&&j<=k;j++,k=N-i-j)
         cout++;
 printf("\n%d Apple Have %d case\n",N,cout);
 getch();
}
最后结果显示 8 种



 
											





 
	    

 
	



