1 solutions
-
0
C++ :
#include<iostream> #include<cstring> using namespace std; int r,c; int a[100][100]; void init(); int my_max(int,int,int,int); int main() { init(); int i=1,j=1,tot=0,k; while(1) { tot+=a[i][j]; a[i][j]=-1; if(i==r&&j==c) break; k=my_max(a[i-1][j],a[i+1][j],a[i][j-1],a[i][j+1]); if(k==1) i--; if(k==2) i++; if(k==3) j--; if(k==4) j++; } cout<<tot<<endl; return 0; } void init() { cin>>r>>c; memset(a,0,sizeof(a)); for(int i=0;i<=c+1;++i) { a[0][i]=-1; a[r+1][i]=-1; } for(int i=0;i<=r+1;i++) { a[i][0]=-1; a[i][c+1]=-1; } for(int i=1;i<=r;++i) { for(int j=1;j<=c;++j) { cin>>a[i][j]; } } /*for(int i=0;i<=r+1;++i) { for(int j=0;j<=c+1;++j) cout<<a[i][j]<<' '; cout<<endl; }*/ } int my_max(int a,int b,int c,int d) { int temp=-1,k=-1; if(a>temp) { temp=a; k=1; } if(b>temp) { temp=b; k=2; } if(c>temp) { temp=c; k=3; } if(d>temp) { temp=d; k=4; } return k; }
- 1
Information
- ID
- 10164
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By