我修改后的代码,谢谢!!!定义的指针,最大只能运行到12 billion.
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include <iostream>
using namespace std;
template<class T>
int DFS_FindNext(T arr[], int nMaxElm, int nDepth)
{
int n = nDepth-1;
for (++arr[n]; n>=0 && arr[n]>=nMaxElm; ++arr[--n]);
if (n<0) return 0;
for (int t = n+1; t<nDepth; ++t) arr[t] = arr[n];
return 1;
};
int main()
{
int n=4,m=19,i,j,v=0,l=0;// 输入m,n
int arr[20]={0};
float c1[20],z1[20];
float *c2,*z2;
c2=(float *)malloc(1200000000*sizeof(float));
z2=(float *)malloc(1200000000*sizeof(float));
c1[0]=0;z1[0]=0;
char outmap[19]={'A','B','S','P','V','T','C','L','N','D','Q','K','E','M','H','F','R','Y','W'};
float c[19]={75.055,89.071,105.066,115.087,117.102,119.082,121.043,
131.1184381,132.045435,133.0171,146.09521,146.12971,147.076,
149.0748591,155.0932861,165.1027881,174.1354851,181.0977,204.113};
float z[19]={60.022935,74.03645,90.0405,100.095,102.096,104.3437,106.0007,116.0837297,
117.0427,118.02687,131.082437,131.0946287,132.0487,134.0407,140.0585777,
150.06797,159.1067,166.0647,189.0787};
FILE *fp1;
fp1=fopen("1.txt","w");
do
{
for(int t=0,i=1;t<n,i<=n;++t,i++)
{
fprintf(fp1,"%c",outmap[arr[t]]); //输出字母的组合
c1[i]=c[arr[t]]+c1[i-1];
z1[i]=z[arr[t]]+z1[i-1];
}
fprintf(fp1,"\t%.7f\t%.7f\t%d\n",c1[n],z1[n],v+1);//输出每种字母组合对应的二个数字
c2[l]=c1[n];z2[l]=z1[n];v++;l++;
//赋予新的数组以便循环比较,问题在于l很大
}while(DFS_FindNext(arr, m, n));
return 0;
fclose(fp1);
}