代码是:
class RandomPancakeStack {
vector<int> *del;
double seen[256][256];
public:
double expectedDeliciousness(vector<int>&);
double dfs(int size, int index);
};
double RandomPancakeStack::dfs(int pos, int remain){
if(pos < 0) return 0.0;
if(seen[pos][remain] != -1) { cout << "seen\n"; return seen[pos][remain];}
double sum = 0.0;
int i;
for(i=0; i <=pos; i++){
cout << " sum += "<< (*del)[i] << " + " << dfs(i-1, remain-1) << endl;
sum += (*del)[i] + dfs(i-1, remain-1);
}
sum /= remain;
cout << " sum /=remain " << sum << endl;
seen[pos][remain] = sum;
return sum;
}
double RandomPancakeStack::expectedDeliciousness(vector<int> &d){
int N = d.size();
int i,j,k;
del = &d;
for(i=0; i < 256; i++){
for(j=0; j < 256; j++){
seen[i][j] = -1;
}
}
return dfs(N-1, N);
是O(N * N)吗?