题解
2023-08-25 09:48:06
发布于:广东
9阅读
0回复
0点赞
#include <cstdio> // 万能头表示你不能用map当数组名
#include <cstring>
#include <algorithm>
#include <iostream>
#include <iomanip>
using namespace std;
const int maxnum = 35;
const int M = 100000000;
typedef unsigned long long ll;
int n, m, map[81][81];
struct highNum
{
ll num[maxnum];
highNum(int length = 1)
{
memset(num, 0, sizeof(num));
num[0] = length;
}
highNum operator = (highNum b)
{
memcpy(num, b.num, sizeof(b.num));
return *this;
}
highNum operator = (int b)
{
*this = highNum();
num[num[0]] = b;
return *this;
}
bool operator < (const highNum& b) const
{
if(num[0] < b.num[0]) return true;
if(num[0] == b.num[0])
{
for(int i = num[0]; i >= 1; --i)
{
if(num[i] > b.num[i]) return false;
if(num[i] < b.num[i]) return true;
}
}
return false;
}
highNum operator + (const highNum& b) const
{
highNum c = highNum(max(num[0], b.num[0]));
for(int i = 1; i <= c.num[0]; ++i)
{
c.num[i] += num[i] + b.num[i];
c.num[i + 1] += c.num[i] / M;
c.num[i] %= M;
}
while(c.num[c.num[0] + 1] > 0)
{
++c.num[0];
c.num[c.num[0] + 1] += c.num[c.num[0]] / M;
c.num[c.num[0]] %= M;
}
return c;
}
highNum operator * (const int b) const
{
highNum c = highNum(num[0]);
for(int i = 1; i <= c.num[0]; ++i)
{
c.num[i] += num[i] * b;
c.num[i + 1] += c.num[i] / M;
c.num[i] %= M;
}
while(c.num[c.num[0] + 1] > 0)
{
++c.num[0];
c.num[c.num[0] + 1] += c.num[c.num[0]] / M;
c.num[c.num[0]] %= M;
}
while(c.num[c.num[0]] == 0 && c.num[0] > 1) --c.num[0];
return c;
}
highNum operator * (const highNum& b) const
{
highNum c = highNum(num[0] + b.num[0]);
for(int i = 1; i <= num[0]; ++i) for(int j = 1; j <= b.num[0]; ++j)
{
c.num[i + j - 1] += num[i] * b.num[j];
c.num[i + j] += c.num[i + j - 1] / M;
c.num[i + j - 1] %= M;
}
while(c.num[c.num[0] + 1] > 0)
{
++c.num[0];
c.num[c.num[0] + 1] += c.num[c.num[0]] / M;
c.num[c.num[0]] %= M;
}
while(c.num[c.num[0]] == 0 && c.num[0] > 1) --c.num[0];
return c;
}
};
ostream& operator << (ostream& o, highNum& b)
{
o << b.num[b.num[0]];
o.setf(ios::fixed);
o.width(8);
o.fill('0');
for(int i = b.num[0] - 1; i >= 1; --i) o << b.num[i];
return o;
}
highNum ans, f[81][81], pw[81];
void init()
{
cin >> n >> m;
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j)
cin >> map[i][j];
pw[1] = 2;
for(int i = 2; i <= m; ++i) pw[i] = pw[i - 1] * 2;
}
void work(int row)
{
for(int i = 1; i <= m; ++i) for(int j = 1; j <= m; ++j)
f[i][j] = highNum();
for(int i = 1; i <= m; ++i) f[i][i] = pw[m] * map[row][i];
for(int p = 1; p < m; ++p) for(int i = 1; i <= m - p; ++i)
{
int j = i + p;
f[i][j] = max(f[i + 1][j] + pw[m - p] * map[row][i], f[i][j - 1] + pw[m - p] * map[row][j]);
}
ans = ans + f[1][m];
}
int main()
{
init();
for(int i = 1; i <= n; ++i) work(i);
cout << ans;
return 0;
}
这里空空如也
有帮助,赞一个