注释了乘法位数的地方,为什么直接l <= len会错?
#include<iostream>
#include<algorithm>
using namespace std;
int f1[60][1000], f2[5];
int main(){
int n, len = 1;
cin >> n;
f1[1][0] = 1;
f1[1][1] = 1;
for(int i = 2; i <= n; i++){
int j = i, k = 1;
while(j){
f2[k] = j % 10;
j /= 10;
k++;
}
f2[0] = k;
for(int l = 1; l <= len + f2[0]; l++) //乘法位数?
for(int m = 1; m <= f2[0]; m++)
f1[i][l + m - 1] += f1[i - 1][l] * f2[m];
for(int l = 1; l <= len + f2[0]; l++)
if(f1[i][l] >= 10){
f1[i][l + 1] += f1[i][l] / 10;
f1[i][l] %= 10;
}
while(f1[i][len + 1]) len++;
f1[i][0] = len;
// cout << "len = " << len << endl;
}
// for(int i = len; i >= 1; i--)
// cout << f1[n][i];
// cout << endl;
for(int i = 2; i <= n; i++){ //加法
for(int j = 1; j <= max(f1[i - 1][0], f1[i][0]); j++)
f1[i][j] += f1[i - 1][j];
for(int k = 1; k <= f1[i][0]; k++)
if(f1[i][k] >= 10){
f1[i][k + 1]++;
f1[i][k] %= 10;
}
while(f1[i][f1[i][0] + 1]) f1[i][0]++;
}
for(int i = f1[n][0]; i >= 1; i--)
cout << f1[n][i];
return 0;
}