1 条题解
-
0
#include <iostream> using namespace std; int n, m, a[2018][2018]; int ans, sum; bool vis[2018][2018]; void dfs(int x, int y) { if (x == n + 1) { ans = max(ans, sum); return; } int nx = x, ny = y + 1; if (ny > m) { ny = 1; nx = x + 1; } if(!vis[x-1][y]&&!vis[x][y-1]&&!vis[x][y+1]&&!vis[x+1][y]&&!vis[x+1][y+1]&&!vis[x-1][y-1]&&!vis[x-1][y+1]&&!vis[x+1][y-1]){ vis[x][y]=1; sum+=a[x][y]; dfs(nx,ny); vis[x][y]=0; sum-=a[x][y]; } dfs(nx, ny); } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; dfs(1, 0); cout << ans; return 0; }//Demon
- 1
信息
- ID
- 72
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- 递交数
- 9
- 已通过
- 3
- 上传者