标签:
3 4
3 3 4 5
4 5 3 2
1 7 4 2
39
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #define inf 0x7fffffff 6 using namespace std; 7 int r,c;//r hang c lie 8 int xx[5]={0,1,0,-1},yy[5]={1,0,-1,0};//xia you shang zuo 9 int a[45][45]; 10 int ans=0; 11 void dfs(int x,int y)//x hang y lie 12 { 13 ans+=a[x][y]; 14 if(x==r&&y==c)return ; 15 a[x][y]=-1; 16 int mxx=0,mxy=0; 17 for(int d=0;d<4;d++) 18 { 19 int dx=x+xx[d],dy=y+yy[d]; 20 if(a[dx][dy]>a[mxx][mxy]) 21 { 22 mxx=dx; 23 mxy=dy; 24 } 25 } 26 dfs(mxx,mxy); 27 } 28 29 int main() 30 { 31 cin>>r>>c; 32 for(int i=1;i<=r;i++)for(int j=1;j<=c;j++)scanf("%d",&a[i][j]); 33 dfs(1,1); 34 cout<<ans; 35 puts(""); 36 return 0; 37 }
找过的格子别忘了标记一下QAQ
标签:
原文地址:http://www.cnblogs.com/gc812/p/5798982.html