当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

 ·datagrid怎么与数据相连    »显示摘要«
    摘要: 在access的窗体上放datagrid,怎么与ado相连呀? 若使用recordset as adodb.recordset对象怎么连? ......
    摘要: please tell me the order of learning. uml rose design partern vc++ vc# vb.net visio xp data structure system platform ......


如何用递归快速求出解呢

有一堆长度为90的木材A,而需要一批长度分别  
  40   ,25,30,20(这一组数据可增,可减,变化的)的木材。  
   
  请问A类木材有几种分割法呢?  
   
  所以的分割方法列表如下:如何用递归法求出?  
   
  90  
   
  40 25 30 20  
   
  1 2 0 0 0 一根a只能分二根40  
  2 1 2 0   0               一根a可分一根40,二根25    
  3 1 1 0 1 a   可分一根40   一根25         一根20的  
  4 0 3 0 0 ...  
  5 0 2 1 0 ...  
  6 0 2 0 2 ...  
  7 0 1 2 0 ...  
  8 0 1 1 1 ...  
  9 0 0 3 0 ...  
  10 0 0 2 1 ...  
  11 0 0 1 3   ...  
  12 0 0 0 4               ...

NO.1   作者: ZhangYv

1根好求,N根的话还是装箱问题,无有效算法。

NO.2   作者: lymgf

既然楼主说递归就递归吧,废话就不多说啦,看代码:  
   
  #include   <stdio.h>  
   
  #define   A   90  
  #define   S   4  
   
  int   wood[S]={40,25,30,20};  
  int   out[S];  
  int   count=0;  
   
  void   Divide(int   len,int   style)  
  {  
  int   i;  
   
  if   (style==S-1)  
  {  
  count++;  
  out[style]=len/wood[style];  
  printf("%3d",count);  
  for   (i=0;i<S;i++)  
  printf("%5d",out[i]);  
  printf("\n");  
  }  
  else  
  {  
  for   (i=len/wood[style];i>=0;i--)  
  {  
  out[style]=i;  
  Divide(len-i*wood[style],style+1);  
  }  
  }  
  }  
   
  int   main()  
  {  
  int   i;  
   
  printf("NO.");  
  for   (i=0;i<S;i++)  
  printf("%5d",wood[i]);  
  printf("\n");  
   
  Divide(A,0);  
  }


    摘要: 求助:paradox表中要查某字段中记录为空(也就是什么都没有)的记录,如何实现? select * from table where field = 是行不通的! ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE