「杂题乱刷」AT_abc358_g

代码恢复训练 2024.6.15(补)

链接 (luogu)

链接 (atcoder)

abc 最水的 G 了吧。

你发现,你最后肯定全在在同一个点上不动,而且你一定可以在 \(n \times m\) 回合内走到这个点,因此我们直接 \(dp_{i,x,y}\) 表示走 \(i\) 步到 \((x,y)\) 这个格子所能得到的最大值即可。

时间复杂度 \(O(n^2m^2)\)

代码:

点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
打 cf 不要用 umap!!!

记住,rating 是身外之物。

该冲正解时冲正解!

Problem:

算法:

思路:

*/
#include<bits/stdc++.h>
using namespace std;
//#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define forll(i,a,b,c) for(register long long i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(register long long i=a;i>=b;i-=c)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid ((l+r)>>1)
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) (x&-x)
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
#define ull unsigned long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
#define aty cout<<"Yes\n";
#define atn cout<<"No\n";
#define cfy cout<<"YES\n";
#define cfn cout<<"NO\n";
#define xxy cout<<"yes\n";
#define xxn cout<<"no\n";
#define printcf(x) x?cout<<"YES\n":cout<<"NO\n";
#define printat(x) x?cout<<"Yes\n":cout<<"No\n";
#define printxx(x) x?cout<<"yes\n":cout<<"no\n";
ll t;
ll n,m,k;
ll sx,sy,ans;
ll a[60][60];
ll dx[]={0,0,1,-1,0},dy[]={1,-1,0,0,0};
ll dp[60*60][60][60];
bool check(ll x,ll y){
	return x>=1 && x<=n && y>=1 && y<=m;
} 
void solve()
{
	cin>>n>>m>>k>>sx>>sy;
	forl(i,1,n)
		forl(j,1,m)
			cin>>a[i][j];
	forl(i,0,59)
		forl(j,0,59)
			forl(l,0,60*60-1)
				dp[l][i][j]=-1e18;
	dp[0][sx][sy]=0;
	forl(i,1,min(n*m,k))
		forl(j,1,n)
			forl(l,1,m)
			{
				forl(x,0,4)
				{
					ll fx=j+dx[x],fy=l+dy[x];
					if(check(fx,fy))
						dp[i][fx][fy]=max(dp[i][fx][fy],dp[i-1][j][l]+a[fx][fy]),ans=max(ans,dp[i][fx][fy]);
				}
			}
	forl(i,1,n)
		forl(j,1,m)
			forl(l,1,min(k,n*m))
				ans=max(ans,dp[l][i][j]+a[i][j]*(k-l));
	cout<<ans<<endl;
}
int main()
{
	IOS;
	t=1;
 //	cin>>t;
	while(t--)
		solve();
    /******************/
	/*while(L<q[i].l) */
	/*    del(a[L++]);*/
	/*while(L>q[i].l) */
	/*    add(a[--L]);*/
	/*while(R<q[i].r) */
	/*	  add(a[++R]);*/
	/*while(R>q[i].r) */
	/*    del(a[R--]);*/
    /******************/
	QwQ;
}
posted @ 2024-06-16 22:49  wangmarui  阅读(4)  评论(0编辑  收藏  举报