Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
居然16ms输入只要求一组数据,遍历所有子矩阵,不知道如何提高了。 int N; int** input; int *arrrow, *arr; int i; scanf("%d", &N); //while(scanf("%d", &N),N) //{ input = new int*[N]; for (i=0; i<N; i++) { input[i] = new int[N]; for(int j=0; j<N; j++) { scanf("%d", &input[i][j]); } } int max = -999999; arrrow = new int[N];// sum of row arr = new int[N]; // sum of sub rectangle for (i=0; i<N; i++)// sub-rectangle start line { memset(arrrow, 0, sizeof(int)*N); for (int j=i; j<N; j++)// i line to N line { memset(arr,0, sizeof(int)*N); for (int k=0; k<N; k++)// sub-rectangle row { arrrow[k] += input[j][k]; if ( arr[k==0?0:k-1]+arrrow[k]>arr[k==0?0:k-1]) { arr[k] = arr[k==0?0:k-1] + arrrow[k]; if (arr[k]>max) max = arr[k]; }else{ arr[k]=0; if (arr[k]>max) max = arr[k]; } } } } printf("%d", max); //} return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator