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 |
我把楼上“一种解法”的代码稍微整理了下,清晰度会好一些,而且考虑了单个元素最大的情况#include <stdio.h> #include <stdlib.h> int main() { int n,res; int data[100][100]; int s[101],a[100]; while(scanf("%d",&n)==1) { /* input data */ for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { scanf("%d",&data[i][j]); } } res = data[0][0]; for(int i=0;i<n;i++) { for(int j=i;j<n;j++) { /* initial */ for(int t=0;t<100;t++) { a[t]=0; s[t]=0; } for(int col=0;col<n;col++) { for(int row=i;row<=j;row++) a[col]+=data[row][col]; if(s[col]>0) s[col+1]=a[col]+s[col]; else s[col+1]=a[col]; } for(int t=1;t<=n;t++) { if(res<s[t]) res=s[t]; } } } printf("%d",res); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator