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 |
这样也会超时?感觉和那个0MS的人的算法没什么区别啊?? 为什么总是超时? 谁能给几组测试数据吗?? 反正讨论区的测试数据都是瞬间出答案的,问题在哪里啊??哪位好心的人能帮个忙啊? #include<iostream> using namespace std; int height[102][102]; int length[102][102]; int longest=0,longestnow; int r,c; int search(int x,int y) { if(length[x][y]>=longestnow) longestnow=length[x][y]; if(height[x][y]>height[x+1][y]) { if(length[x+1][y]<=length[x][y]) { length[x+1][y]=length[x][y]+1; search(x+1,y); } } if(height[x][y]>height[x-1][y]) { if(length[x-1][y]<=length[x][y]) { length[x-1][y]=length[x][y]+1; search(x-1,y); } } if(height[x][y]>height[x][y+1]) { if(length[x][y+1]<=length[x][y]) { length[x][y+1]=length[x][y]+1; search(x,y+1); } } if(height[x][y]>height[x][y-1]) { if(length[x][y-1]<=length[x][y]) { length[x][y-1]=length[x][y]+1; search(x,y-1); } } return 0; } int main() { int i,j,i1,j1; cin>>r>>c; for(i=0;i<=r;i++) height[i][0]=10001; for(i=0;i<=r;i++) height[i][c+1]=10001; for(i=0;i<=c;i++) height[0][i]=10001; for(i=0;i<=c;i++) height[r+1][i]=10001; for(i=1;i<=r;i++) for(j=1;j<=c;j++) cin>>height[i][j];//initialization for(i=1;i<=r;i++) for(j=c;j>0;j--) { for(i1=r;i1>0;i1--) for(j1=1;j1<=c;j1++) { length[i1][j1]=0; } longestnow=0; length[i][j]=1; if(longest<height[i][j]) { search(i,j); } if(longestnow>longest) longest=longestnow; } cout<<longest; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator