| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 741 人关注过本帖
标题:请求帮助----如何加快以下函数“递归调用”的速度???
取消只看楼主 加入收藏
spring4676
Rank: 1
来 自:内蒙古大草原
等 级:新手上路
帖 子:103
专家分:0
注 册:2007-12-10
结帖率:100%
收藏
 问题点数:0 回复次数:1 
请求帮助----如何加快以下函数“递归调用”的速度???
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 18
子函数
double nm(double s[N][N],double n)
{
  int z,j,k;
  double r;
  double total=0;
  double b[N][N];
  if(n>2)
  {for(z=0;z<n;z++)
   {
   for(j=0;j<n-1;j++)
   for(k=0;k<n-1;k++)
   if(k>=z)    b[j][k]=s[j+1][k+1];
    else        b[j][k]=s[j+1][k];
   if(z%2==0)     r=s[0][z]*nm(b,n-1);
   else        r=(-1)*s[0][z]*nm(b,n-1);
   total=total+r;
   }
  }
  else if(n==2) total=s[0][0]*s[1][1]-s[0][1]*s[1][0];
  return total;
}

void main()
{
  double r;
  int z,j;
  double A[N][N]={216.080575,64.334189,81.390948,18.961460,68.975034,27.294921,51.867969,45.292775,35.914893,7.521622,281.840523,85.170013,113.368330,43.404363,79.075082,37.928194,0.217347,-13.917258,64.334189,173.644630,29.905901,35.448366,45.154975,31.266095,29.807213,43.429087,19.340695,2.290508,89.890442,194.873946,75.549009,56.832321,42.550892,29.080924,-0.007042,-8.624715,81.390948,29.905901,174.683588,68.325187,61.123854,31.642574,53.842455,40.558928,49.622104,29.259359,203.933440,65.556207,137.770223,56.018970,100.427963,59.807900,-0.150143,
              -11.238649,18.961460,35.448366,68.325187,175.865120,24.453967,43.260467,24.193681,40.074647,41.534978,18.708799,69.247443,133.115593,67.498953,94.802646,72.022466,55.270277,-0.408724,-10.479285,68.975034,45.154975,61.123854,24.453967,141.953937,49.716873,
              66.925312,42.642363,38.775535,21.233530,111.618312,59.066859,189.700856,57.400850,87.164045,48.988829,0.024556,-8.612514,27.294921,31.266095,31.642574,43.260467,49.716873,153.129815,31.652469,39.068692,14.225421,12.953286,49.846551,61.019389,92.166231,169.800335,34.857269,39.493383,0.013448,-0.530932,51.867969,29.807213,53.842455,24.193681,66.925312,31.652469,206.268636,78.059095,86.545681,33.817465,88.212286,46.189150,125.668648,63.964354,221.845322,78.611909,-1.081465,-38.989956,45.292775,43.429087,40.558928,40.074647,42.642363,39.068692,
              78.059095,188.133364,41.643669,22.573052,76.069968,62.405447,93.429627,107.074706,114.737454,126.738944,-0.267784,2.130718,35.914893,19.340695,49.622104,41.534978,38.775535,14.225421,86.545681,41.643669,162.796715,73.911290,69.510721,42.928588,68.689044,39.883913,232.303029,103.287443,-0.743439,-18.503976,7.521622,2.290508,29.259359,18.708799,21.233530,12.953286,33.817465,22.573052,73.911290,136.593139,24.401305,13.649131,46.964047,24.883234,
              100.996075,154.586991,-0.101866,-2.213120,281.840523,89.890442,203.933440,69.247443,111.618312,49.846551,88.212286,76.069968,69.510721,24.401305,468.776876,151.051992,201.176534,81.772231,152.932497,76.280851,0.121161,-19.187441,85.170013,194.873946,65.556207,133.115593,59.066859,61.019389,46.189150,62.405447,42.928588,13.649131,151.051992,329.425002,106.641292,104.912166,84.153993,55.677761,-0.157045,-13.126074,113.368330,75.549009,137.770223,67.498953,189.700856,92.166231,125.668648,93.429627,68.689044,46.964047,201.176534,106.641292,
              341.917676,142.259597,148.818899,103.055353,-0.206649,-8.938765,43.404363,56.832321,56.018970,94.802646,57.400850,169.800335,63.964354,107.074706,39.883913,24.883234,81.772231,104.912166,142.259597,303.516296,86.287722,73.284537,-0.374199,-1.978616,79.075082,42.550892,100.427963,72.022466,87.164045,34.857269,221.845322,114.737454,232.303029,100.996075,152.932497,84.153993,148.818899,86.287722,438.431991,180.521131,-1.578421,-48.088285,
              37.928194,29.080924,59.807900,55.270277,48.988829,39.493383,78.611909,126.738944,103.287443,154.586991,76.280851,55.677761,103.055353,73.284537,180.521131,270.824517,-0.240789,-1.566335,0.217347,-0.007042,-0.150143,-0.408724,0.024556,0.013448,-1.081465,-0.267784,-0.743439,-0.101866,0.121161,-0.157045,-0.206649,-0.374199,-1.578421,-0.240789,0.033235,0.148869,-13.917258,-8.624715,-11.238649,-10.479285,-8.612514,-0.530932,-38.989956,2.130718,-18.503976,-2.213120,-19.187441,-13.126074,-8.938765,-1.978616,-48.088285,-1.566335,0.148869,30.836197};
  printf("\nThe old matrix is :\n");
  for(z=0;z<N;z++)
  {
    for(j=0;j<N;j++)
      printf("%f\t",A[z][j]);
    printf("\n");
  }
  r=nm(A,N);
  printf("\nThe is:|A|== %f \n",r);
}
搜索更多相关主题的帖子: 递归调用 函数 速度 请求 
2008-01-01 22:53
spring4676
Rank: 1
来 自:内蒙古大草原
等 级:新手上路
帖 子:103
专家分:0
注 册:2007-12-10
收藏
得分:0 
A[N][N]数组里N变大时,运行速度急速下降!
关键是当A[N][N]数组里的N增加到16时,程序运行的就非常慢了,有没有什么办法让程序运行的更快一些?,
2008-01-02 09:06
快速回复:请求帮助----如何加快以下函数“递归调用”的速度???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013985 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved