P11065 【MX-X4-T5】「Jason-1」占领高地

仅设在 (1,1) 不行
by jason_sun @ 2024-09-17 09:44:59


不仅设在 (1,1) 不满足安全程度最大
by jason_sun @ 2024-09-17 09:47:06


@[jason_sun](/user/399762) 为啥
by 违规用户名Jx9)zIu @ 2024-09-17 10:00:05


``` #include<bits/stdc++.h> using namespace std; int n,m; int h[305][305]; int p[305][305]; int f; int a,b,c,d; int dfs(int x,int y,bool l,int k,int w,int u){ for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(i==x&&j==y){ }else{ if(h[i][j]-h[x][y]+p[i][j]>=abs(x-i)+(y-j)){ if(l==0){ if(i==a&&j==b){ dfs(x,y,1,min(k,h[i][j]),i,j); }else{ dfs(x,y,0,min(k,h[i][j]),i,j); } }else{ if(i==c&&j==d){ return k; }else{ dfs(x,y,1,min(k,h[i][j]),i,j); } } } } } } return -1; } void slove(){ f=min(h[a][b],h[c][d]); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(i==a&&j==b){ int s=dfs(i,j,1,f,0,0); max(s,f); }else{ int s=dfs(i,j,0,f,0,0); max(s,f); } } } cout<<f<<endl; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q; cin>>n>>m>>q; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>h[i][j]; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>p[i][j]; } } while(q--){ cin>>a>>b>>c>>d; slove(); } exit(0); } ``` 我的代码会MLE
by 违规用户名Jx9)zIu @ 2024-09-17 10:01:10


|