The Code submitted for the first time uses recursion. Due to the large number of recursive layers of data, stack overflow occurs ".
Code submitted for the first time:
// Template start # include <string> # include <vector> # include <algorithm> # include <iostream> # include <sstream> # include <fstream> # include <map> # include <set> # include <cstdio> # include <cmath> # include <cstdlib> # include <ctime> # include <iomanip> # define SZ (X) (INT (X. size () using namespace STD; int toint (string s) {istringstream sin (s); int t; sin> T; return t ;} template <class T> string tostring (t x) {ostrings Tream sout; sout <X; return sout. STR ();} typedef long int64; int64 toint64 (string s) {istringstream sin (s); int64 t; sin> T; return t ;} template <class T> T gcd (t a, t B) {if (a <0) return gcd (-a, B); If (B <0) return gcd (A,-B); Return (B = 0 )? A: gcd (B, A % B);} // template end (General Part) // [exercise 09] Simple Dynamic Planning 1002 Max sum int calculate_add_max (int * datas, int * add_max, Int J, int N) {If (j = n-1) {return datas [n-1];} else {add_max [J + 1] = calculate_add_max (datas, add_max, J + 1, n); If (add_max [J + 1]> 0) {return datas [J] + add_max [J + 1];} else {return datas [J] ;}} int main () {ifstream ifs ("shuju.txt", IOS:: In); INT cases; int N; int datas [100005]; int add_max [1000 05]; // ifs> cases; CIN> cases; for (INT I = 0; I <cases; I ++) {// ifs> N; cin> N; For (Int J = 0; j <n; j ++) {// ifs> datas [J]; CIN> datas [J];} add_max [0] = calculate_add_max (datas, add_max, 0, n); int max = add_max [0]; int max_index = 0; For (Int J = 0; j <N; j ++) {If (add_max [J]> MAX) {max = add_max [J]; max_index = J ;}} Int J; For (j = max_index + 1; j <n; j ++) {If (add_max [J] <= 0) {cout <"case" <I + 1 <":" <Endl; c Out <add_max [max_index] <"" <max_index + 1 <"" <j <Endl; if (I! = Cases-1) {cout <Endl;} break;} else {continue;} If (j = N) {cout <"case" <I + 1 <":" <Endl; cout <add_max [max_index] <"" <max_index + 1 <"" <n <Endl; if (I! = Cases-1) {cout <Endl ;}} return 0 ;}
Instead of recursion, the AC is successfully switched to recursion.
The second code submission:
// Template start # include <string> # include <vector> # include <algorithm> # include <iostream> # include <sstream> # include <fstream> # include <map> # include <set> # include <cstdio> # include <cmath> # include <cstdlib> # include <ctime> # include <iomanip> # define SZ (X) (INT (X. size () using namespace STD; int toint (string s) {istringstream sin (s); int t; sin> T; return t ;} template <class T> string tostring (t x) {ostrings Tream sout; sout <X; return sout. STR ();} typedef long int64; int64 toint64 (string s) {istringstream sin (s); int64 t; sin> T; return t ;} template <class T> T gcd (t a, t B) {if (a <0) return gcd (-a, B); If (B <0) return gcd (A,-B); Return (B = 0 )? A: gcd (B, A % B);} // template end (General Part) // [exercise 09] Simple Dynamic Planning 1002 Max sum int calculate_add_max (int * datas, int * add_max, Int J) {return add_max [J + 1]> 0? Datas [J] + add_max [J + 1]: datas [J];} int main () {ifstream ifs ("shuju.txt", IOS: In); INT cases; int N; int datas [100005]; int add_max [100005]; // ifs> cases; CIN> cases; for (INT I = 0; I <cases; I ++) {// ifs> N; CIN> N; For (Int J = 0; j <n; j ++) {// ifs> datas [J]; CIN> datas [J];} add_max [n-1] = datas [n-1]; for (Int J = N-2; j> = 0; j --) {add_max [J] = calculate_add_max (datas, add_max, J );} int max = add_max [0]; int Max_index = 0; For (Int J = 0; j <n; j ++) {If (add_max [J]> MAX) {max = add_max [J]; max_index = J ;}} Int J; For (j = max_index + 1; j <n; j ++) {If (add_max [J] <= 0) {cout <"case" <I + 1 <":" <Endl; cout <add_max [max_index] <"" <max_index + 1 <"" <j <Endl; if (I! = Cases-1) {cout <Endl;} break;} else {continue;} If (j = N) {cout <"case" <I + 1 <":" <Endl; cout <add_max [max_index] <"" <max_index + 1 <"" <n <Endl; if (I! = Cases-1) {cout <Endl ;}} return 0 ;}