我又总结了一种动归模型……

这道题和上一道题很类似,都是给一个序列,然后相邻的元素可以合并

然后合并后的元素可以再次合并

那么就可以用这两道题类似的方法解决

简单来说就是枚举区间,然后枚举断点

加上断点左右两边的值(按照题目,可能不是加),然后在按题目加上计算合并后总的序列的值

就这一道题而言f[i][j] = max(f[i][k] + f[k+1][j] + a[i] * a[(k+1)%n] * a[(j+1)%n]); 题目中变化的可能就是

合并后总的序列的值的计算方式

万变不离其宗

#include<cstdio>
#include<cstring>
#include<algorithm>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
using namespace std; const int MAXN = 112;
int f[MAXN][MAXN], a[MAXN], b[MAXN]; int main()
{
int n;
scanf("%d", &n);
REP(i, 0, n) scanf("%d", &b[i]); int ans = 0;
REP(r, 0, n)
{
memset(f, 0, sizeof(f));
REP(i, 0, n) a[i] = b[(i+r) % n];
REP(d, 2, n + 1)
for(int st = 0; st + d - 1 < n; st++)
{
int i = st, j = st + d - 1;
REP(k, i, j)
f[i][j] = max(f[i][j], f[i][k] + f[k+1][j] + a[i] * a[(k+1)%n] * a[(j+1)%n]);
}
ans = max(ans, f[0][n - 1]);
} printf("%d\n", ans); return 0;
}

最新文章

  1. Windows Azure Virtual Machine 之用程序控制Azure VM
  2. RedGate .NET Reflector注册问题(反注册)
  3. Activity(一)
  4. UVALive - 6572 Shopping Malls floyd
  5. handler looper 和 线程
  6. Web Service学习之九:Restful WebService
  7. 简单的玩玩etimer &lt;contiki学习笔记之九 补充&gt;
  8. 【IT历史】SP和CP
  9. PAT (Advanced Level) 1025. PAT Ranking (25)
  10. javascript之数组快速排序
  11. CLR类型设计之泛型(一)
  12. Navicat如何进行搜索筛选
  13. 【数据库】MySql分割字符串
  14. 1. ansible-playbook 变量定义与引用
  15. 异步任务利器Celery(二)在django项目中使用Celery
  16. php CURL 发送get,post请求
  17. cp自动创建层级结构的例子
  18. [转帖] Linux buffer 和 cache相关内容
  19. 6 Easy Steps to Learn Naive Bayes Algorithm (with code in Python)
  20. maven 笔记:maven Could not create the Java Virtual Machine

热门文章

  1. vs2015汉化
  2. 【原创】ActiveMQ集群JDBC持久化
  3. MySQL存储过程和自定义函数、Navicat for mysql、创建存储过程和函数、调用存储过程和函数的区别
  4. ZBrush笔刷属性栏简介
  5. Set集合[HashSet,TreeSet,LinkedHashSet],Map集合[HashMap,HashTable,TreeMap]
  6. LA3231 Fair Share 二分_网络流
  7. svn 验证位置失败 Authorization failed
  8. centos7 jumpserver 部署和使用手册(一)
  9. ip iproute2的典型应用
  10. vue中使用viewerjs