标签:洛谷 int depth num maxn 1005 include dp
1.不要贪,缩小区间去dp就好。
2.预处理指数。
3.__int128可还行。
1 #include <cstdio> 2 #include <cctype> 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 using namespace std; 7 8 template <typename T> void read(T &x) { 9 x = 0; 10 int s = 1, c = getchar(); 11 for (; !isdigit(c); c = getchar()) 12 if (c == '-') s = -1; 13 for (; isdigit(c); c = getchar()) 14 x = x * 10 + c - 48; 15 x *= s; 16 } 17 18 template <typename T> void write(T x) { 19 if (x < 0) x = -x, putchar('-'); 20 if (x > 9) write(x / 10); 21 putchar(x % 10 + '0'); 22 } 23 24 template <typename T> void writeln(T x) { 25 write(x); 26 puts(""); 27 } 28 29 const int maxn = 81; 30 31 __int128 f[maxn][maxn], p[maxn], num[maxn], ans; 32 33 __int128 dp(int l, int r, int depth) { 34 if (l == r) f[l][r] = num[l] * p[depth]; 35 if (f[l][r] >= 0) return f[l][r]; 36 return f[l][r] = max(num[l] * p[depth] + dp(l + 1, r, depth + 1), num[r] * p[depth] + dp(l, r - 1, depth + 1)); 37 } 38 39 int main() { 40 int n, m; 41 read(n), read(m); 42 p[0] = 1; 43 for (int i = 1; i <= m; i++) 44 p[i] = p[i - 1] * 2; 45 for (int i = 1; i <= n; i++) { 46 for (int j = 1; j <= m; j++) 47 read(num[j]); 48 memset(f, -1, sizeof f); 49 ans += dp(1, m, 1); 50 } 51 writeln(ans); 52 return 0; 53 }
标签:洛谷,int,depth,num,maxn,1005,include,dp 来源: https://www.cnblogs.com/AlphaWA/p/10527909.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。