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> main(){ int pay[100][100]; int get[100][100]; int a[100][100]; int n,m,i,j,cur,k,max; scanf("%d %d",&n,&m); while(n!=0&&m!=0) { for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ scanf("%d ",&pay[i][j]); } } for(i=1;i<=m;i++){ for(j=1;j<=m;j++){ scanf("%d ",&get[i][j]); } } for(j=1;j<=n;j++) a[1][j]=get[1][j]-pay[1][j]; for(i=2;i<=m;i++) { for(j=1;j<=n;j++) { a[i][j]=0; for(k=1;k<=n;k++) { cur=a[i-1][k]+get[i][j]-pay[k][j]; if(a[i][j]<cur) a[i][j]=cur; } } } max=a[m][1]; for(i=1;i<=n;i++) { if(a[m][i]>max) max=a[m][i]; } printf("%d",max); scanf("%d %d",&n,&m); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator