矩陣取數遊戲
阿新 • • 發佈:2018-12-09
https://www.luogu.org/problemnew/show/P1005
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG using namespace std; typedef long long ll; typedef __int128 lll; const int N=10000; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m; lll dp[100][100]; lll ans=0; void print(__int128 x) { if (x>9) print(x/10); putchar('0'+x%10); } int main() { #ifdef DEBUG freopen("input.in", "r", stdin); //freopen("output.out", "w", stdout); #endif scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ memset(dp,0,sizeof(dp)); for(int j=1;j<=m;j++){ scanf("%d",&dp[j][j]); } for(int j=1;j<m;j++){ for(int k=1;k<=m-j;k++){ dp[k][j+k]=max(dp[k+1][j+k]*2+dp[k][k],dp[k][j+k-1]*2+dp[j+k][j+k]); } } ans+=dp[1][m]*2; } print(ans); cout << endl; //cout << "Hello world!" << endl; return 0; }