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 |
不能再短了,回去学动态规划咯!In Reply To:暴力的下场是超时!! Posted by:eleapple at 2005-10-10 01:03:41 #include<stdio.h> #include<stdlib.h> int sumofsubrect(int **s, int r1, int c1, int r2, int c2) { int sum=0,i,j; for(i=r1;i<=r2;i++) for(j=c1;j<=c2;j++) sum=sum+s[i][j]; return sum; } int main() { int i,j,n,max,r,c,temp,okmax,**s; scanf("%d",&n); s=(int**)malloc(n*sizeof(int*)); for(i=0;i<n;i++) s[i]=(int*)malloc(n*sizeof(int)); for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&s[i][j]); okmax=s[0][0]; for(i=0;i<n;i++) for(j=0;j<n;j++) { max=s[i][j]; for(r=0;r<=i;r++) for(c=0;c<=j;c++) { temp=sumofsubrect(s,r,c,i,j); if(temp>max) max=temp; } if(max>okmax) okmax=max; } printf("%d\n",okmax); return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator