1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| #include <iostream> #include <cmath> #include <cstring> #include <algorithm> #include <cstdio> using namespace std;
const int MAXN = 85; const int Mod = 10000; int n, m; int a[85][85];
struct HP { int p[15], len; HP() { memset(p, 0, sizeof p); len = 0; } void print() { printf("%d", p[len]); for (int i = len - 1; i > 0; i--) { if (p[i] == 0) { printf("0000"); continue; } for (int k = 10; k * p[i] < Mod; k *= 10) printf("0"); printf("%d", p[i]); } } } f[MAXN][MAXN][MAXN], base[MAXN], ans;
HP operator + (const HP &a, const HP &b) { HP c; c.len = max(a.len, b.len); int x = 0; for (int i = 1; i <= c.len; i++) { c.p[i] = a.p[i] + b.p[i] + x; x = c.p[i] / Mod; c.p[i] %= Mod; } if (x > 0) c.p[++c.len] = x; return c; }
HP operator * (const HP &a, const int &b) { HP c; c.len = a.len; int x = 0; for (int i = 1; i <= c.len; i++) { c.p[i] = a.p[i] * b + x; x = c.p[i] / Mod; c.p[i] %= Mod; } while (x > 0) c.p[++c.len] = x % Mod, x /= Mod; return c; } HP max(const HP &a, const HP &b) { if (a.len > b.len) return a; else if (a.len < b.len) return b; for (int i = a.len; i > 0; i--) if (a.p[i] > b.p[i]) return a; else if (a.p[i] < b.p[i]) return b; return a; }
void BaseTwo() { base[0].p[1] = 1, base[0].len = 1; for (int i = 1; i <= m + 2; i++){ base[i] = base[i - 1] * 2; } }
int main(){ scanf("%d%d", &n, &m); BaseTwo(); for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ scanf("%d", &a[i][j]); } } for(int k = 1; k <= n; k++){ for(int l = 1; l <= m; l++){ for(int x = 1; x <= m; x++){ if(x + l - 1 > m) continue; f[k][x][x+l-1] = max(f[k][x][x+l-1], f[k][x+1][x+l-1] + base[m-l+1] * a[k][x] ); f[k][x][x+l-1] = max(f[k][x][x+l-1], f[k][x][x+l-2] + base[m-l+1] * a[k][x+l-1]); } } } for(int i = 1; i <= n; i++){ ans = ans + f[i][1][m]; } ans.print(); return 0; }
|