听灌佬多悬赏一关
  • 板块灌水区
  • 楼主LJT_Never_TLE
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/10/20 11:31
  • 上次更新2024/10/20 13:04:27
查看原帖
听灌佬多悬赏一关
1171133
LJT_Never_TLE楼主2024/10/20 11:31

求助P7074

50pts编译结果:https://www.luogu.com.cn/record/183455444

#include <bits/stdc++.h>

// #define ?
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned long long ull;
const int N = 1e3 + 5;
#define mod 1000000007
#define max(a, b) (a < b ? b : a)
#define min(a, b) (a < b ? a : b)
#define rg register
#define endl "\n"

using namespace std;

/*The function of the code was {the functions and ideas...}

/*Functions...*/
inline void IO_Processing()
{
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    std::basic_ios<char>::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
const ll min_ll = -1e9;
ll n, m;
ll a[N][N];
ll f[N][N][2];
inline ll max3(ll p, ll q, ll r)
{
    return p > q ? (p > r ? p : r) : (q > r ? q : r);
}
inline ll DFS(ll x, ll y, ll from)
{
    if (x < 1 || x > n || y < 1 || y > m)
        return min_ll;
    if (f[x][y][from] != min_ll)
        return f[x][y][from];
    if (from == 0)
        f[x][y][from] = max3(DFS(x + 1, y, 0), DFS(x, y - 1, 0), DFS(x, y - 1, 1)) + a[x][y];
    else
        f[x][y][from] = max3(DFS(x - 1, y, 1), DFS(x, y - 1, 0), DFS(x, y - 1, 1)) + a[x][y];
    return f[x][y][from];
}
// Main function↓
int main()
{
    IO_Processing();

    cin >> n >> m;
    for (rg int i = 1; i <= n; ++i)
    {
        for (rg int j = 1; j <= n; ++j)
        {
            cin >> a[i][j];
            f[i][j][0] = f[i][j][1] = min_ll;
        }
    }
    f[1][1][0] = f[1][1][1] = a[1][1];
    cout << DFS(n, m, 1);
    // You Code Main function here
    puts("\n");
    return (0);
}
2024/10/20 11:31
加载中...