|
|
вернуться в форумJUDGE? I wrote a primitive solution for this problem (there were more efficient ones discussed here, but I tried to solve task by myself first). But that's not a point. It crashed again and again with "Stack Overflow", though I can't understand why. It is correct: I compiled it with GCC-G++, generated precalculations and get AC. But why "Stack Overflow"? [C++] #include <iostream> #include <cstring> using namespace std; int main() { int n; double f[501][501]; memset(f, 0, sizeof(f)); cin >> n; f[2][2] = 1; for (int i = 3; i <= n; i++) { f[i][i] = 1; for (int j = 1; j <= i; j++) for (int k = j + 1; k < n; k++) f[i][j] += f[i-j][k]; } double sum = 0; for (int i = 1; i < n; i++) sum += f[n][i]; cout.precision(0); cout.setf(ios_base::fixed); cout << sum << endl; return 0; } Re: JUDGE? Stack size is 1MB. Size of array "b" is about 2MB. To avoid "Stack Overflow" you can: 1. declare "b" as global varialbe; 2. add directive (see also http://acm.timus.ru/help.aspx?topic=cpp) #pragma comment(linker, "/STACK:16777216") Re: JUDGE? 1Mb? Strange, that only now I expirienced this. Thank you! |
|
|