我理解的题意:(70pt)
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int ans=0;
struct nod{
int x,y;
int n;
}b[505];
int tot;
int cmp(nod aa,nod bb)
{
return aa.n>bb.n;
}
int dis(int aa,int bb)
{
if(aa==0) return b[bb].x;
if(bb==0) return b[aa].x;
return min(dis(aa,0)+dis(0,bb),abs(b[aa].x-b[bb].x)+abs(b[aa].y-b[bb].y));
}
int main()
{
cin>>n>>m>>k;
int aa;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>aa;
tot++;
b[tot].x=i,b[tot].y=j,b[tot].n=aa;
}
}
sort(b+1,b+1+tot,cmp);
int now=0;
for(int i=1;i<=tot;i++)
{
if(now+dis(i-1,i)+1+dis(i,0)<=k) now+=dis(i-1,i)+1,ans+=b[i].n;
else break;
// cout<<now<<" "<<ans<<endl;
}
cout<<ans<<endl;
return 0;
}
```
AC代码:
```cpp
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int ans=0;
struct nod{
int x,y;
int n;
}b[505];
int tot;
int cmp(nod aa,nod bb)
{
return aa.n>bb.n;
}
int dis(int aa,int bb)
{
if(aa==0) return b[bb].x;
if(bb==0) return b[aa].x;
return min(dis(aa,0)+dis(0,bb)+9999999,abs(b[aa].x-b[bb].x)+abs(b[aa].y-b[bb].y));
}
int main()
{
cin>>n>>m>>k;
int aa;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>aa;
tot++;
b[tot].x=i,b[tot].y=j,b[tot].n=aa;
}
}
sort(b+1,b+1+tot,cmp);
int now=0;
for(int i=1;i<=tot;i++)
{
if(now+dis(i-1,i)+1+dis(i,0)<=k) now+=dis(i-1,i)+1,ans+=b[i].n;
else break;
// cout<<now<<" "<<ans<<endl;
}
cout<<ans<<endl;
return 0;
}
```
by 入户功夫 @ 2020-11-24 21:36:46
同感,卡了好久,去看了题解才发现似乎没有必要考虑这种情况。
by 紫银 @ 2021-02-04 11:23:02
~~后面那个是tlqtj?jbl(雾~~
by Ja50nY0un9_as_AgNO3 @ 2021-08-31 17:03:39
同问,我也是这样做的结果只得了50pts
by LongLiveMarx @ 2022-07-25 12:21:30
现在有说了
by Shen_Linwood @ 2023-12-13 21:11:22