caioj 1075 动态规划入门(中链式2:能量项链)(中链式dp总结)
2024-08-31 13:39:13
我又总结了一种动归模型……
这道题和上一道题很类似,都是给一个序列,然后相邻的元素可以合并
然后合并后的元素可以再次合并
那么就可以用这两道题类似的方法解决
简单来说就是枚举区间,然后枚举断点
加上断点左右两边的值(按照题目,可能不是加),然后在按题目加上计算合并后总的序列的值
就这一道题而言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;
}
最新文章
- Windows Azure Virtual Machine 之用程序控制Azure VM
- RedGate .NET Reflector注册问题(反注册)
- Activity(一)
- UVALive - 6572 Shopping Malls floyd
- handler looper 和 线程
- Web Service学习之九:Restful WebService
- 简单的玩玩etimer <;contiki学习笔记之九 补充>;
- 【IT历史】SP和CP
- PAT (Advanced Level) 1025. PAT Ranking (25)
- javascript之数组快速排序
- CLR类型设计之泛型(一)
- Navicat如何进行搜索筛选
- 【数据库】MySql分割字符串
- 1. ansible-playbook 变量定义与引用
- 异步任务利器Celery(二)在django项目中使用Celery
- php CURL 发送get,post请求
- cp自动创建层级结构的例子
- [转帖] Linux buffer 和 cache相关内容
- 6 Easy Steps to Learn Naive Bayes Algorithm (with code in Python)
- maven 笔记:maven Could not create the Java Virtual Machine
热门文章
- vs2015汉化
- 【原创】ActiveMQ集群JDBC持久化
- MySQL存储过程和自定义函数、Navicat for mysql、创建存储过程和函数、调用存储过程和函数的区别
- ZBrush笔刷属性栏简介
- Set集合[HashSet,TreeSet,LinkedHashSet],Map集合[HashMap,HashTable,TreeMap]
- LA3231 Fair Share 二分_网络流
- svn 验证位置失败 Authorization failed
- centos7 jumpserver 部署和使用手册(一)
- ip iproute2的典型应用
- vue中使用viewerjs