Markdown是第一生产力
by 勇敢的我 @ 2018-07-17 20:21:13
@[勇敢的我](/space/show?uid=54123) 什么鬼
by 会唱歌的石榴 @ 2018-07-18 10:41:15
改了一下,还是不对,求查错,大佬勿喷
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int a[1001][1001];
bool b[1001][1001];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n,m,k,tot,ans,maxx;
void dfs(int l,int r)
{
b[n][m]=1;
if (l==n && r==m && tot==0)
++tot;
if (l==n && r==m && tot==1)
if (ans>maxx){
maxx=ans;
return;
}
for (int i=1; i<=4; ++i)
if (b[dx[i]+l][dy[i]+r])
{
b[dx[i]+l][dy[i]+r]=false;
ans=ans+a[dx[i]+l][dy[i]+r];
dfs(dx[i]+l,dy[i]+r);
ans=ans-a[dx[i]+l][dy[i]+r];
b[dx[i]+l][dy[i]+r]=true;
}
}
int main()
{
scanf("%d%d",&n,&m);
memset(b,0,sizeof(b));
for (int i=1; i<=n; ++i)
for (int j=1; j<=m; ++j)
{
scanf("%d",&a[i][j]);
b[i][j]=1;
}
maxx=0; ans=0; tot=0;
dfs(1,1);
printf("%d",maxx);
}
by 会唱歌的石榴 @ 2018-07-18 10:43:06
```cpp
include <cstdio>
include <cstring>
include <cmath>
using namespace std;
int a[1001][1001];
bool b[1001][1001];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n,m,k,tot,ans,maxx;
void dfs(int l,int r)
{
b[n][m]=1;
if (l==n && r==m && tot==0)
++tot;
if (l==n && r==m && tot==1)
if (ans>maxx){
maxx=ans;
return;
}
for (int i=1; i<=4; ++i)
if (b[dx[i]+l][dy[i]+r])
{
b[dx[i]+l][dy[i]+r]=false;
ans=ans+a[dx[i]+l][dy[i]+r];
dfs(dx[i]+l,dy[i]+r);
ans=ans-a[dx[i]+l][dy[i]+r];
b[dx[i]+l][dy[i]+r]=true;
}
}
int main()
{
scanf("%d%d",&n,&m);
memset(b,0,sizeof(b));
for (int i=1; i<=n; ++i)
for (int j=1; j<=m; ++j)
{
scanf("%d",&a[i][j]);
b[i][j]=1;
}
maxx=0; ans=0; tot=0;
dfs(1,1);
printf("%d",maxx);
}
```
by rgq233666 @ 2018-07-22 09:50:47
好看多了
by rgq233666 @ 2018-07-22 09:51:00