NOIp2007 矩阵取数游戏

Luogu

像我这种小蒟蒻怎么可能会写高精呢?int128坠好啦

转移方程太显然不写。

#include <cstdio>
#include <cstring>
#include <iostream>

const int max_n = 80 + 5;

int N, M;

__int128 Ans;
__int128 dp[max_n][max_n], Pow[max_n], A[max_n];

inline int read()
{
    register int x = 0;
    register char ch = getchar();
    while(!isdigit(ch))
        ch = getchar();
    while(isdigit(ch))
    {
        x = (x << 1) + (x << 3) + ch - '0';
        ch = getchar();
    }
    return x;
}

inline void out(__int128 x)
{
    if(x > 9) out(x / 10);
    putchar(x % 10 + '0');
}

int main()
{
    N = read(), M = read();
    Pow[0] = 1;
    for(int i = 1; i <= M; ++i)
        Pow[i] = Pow[i - 1] << 1;
    while(N--)
    {
        for(int i = 1; i <= M; ++i)
            A[i] = read();
        memset(dp, 0, sizeof(dp));
        for(int l = M; l >= 1; --l)
            for(int r = l; r <= M; ++r)
                dp[l][r] = std::max(dp[l + 1][r] + A[l] * Pow[M - r + l], dp[l][r - 1] + A[r] * Pow[M - r +l]);
        Ans += dp[1][M];
    }
    out(Ans);
    return 0;
}

转载于:https://www.cnblogs.com/zcdhj/p/8441041.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值