题目链接:

id=1651">点击打开链

题意:

给定一个数组,每次能够选择内部的一个数 i 消除,获得的价值就是 a[i-1] * a[i] * a[i+1]

问最小价值

思路:

dp[l,r] = min( dp[l, i] + dp[i, r] + a[l] * a[i] * a[r]);

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cmath>
using namespace std;
const int N = 105;
const int inf = 100000000;
int a[N], dp[N][N], n;
int dfs(int l, int r){//返回 把区间l,r合并,最后仅仅剩下a[l]和a[r]能获得的最小价值
if(l > r) return 0;
if(dp[l][r] != -1)return dp[l][r];//若区间[l,r]已经计算过则不再计算
if(l == r || l+1 == r) return dp[l][r] = 0;//仅仅有1个或者2个元素则价值是0
int ans = inf;
for(int i = l+1; i < r; i++)
ans = min(ans, a[i] * a[l] * a[r] + dfs(l, i) + dfs(i, r)); return dp[l][r] = ans;
}
int main(){
while(cin>>n){
for(int i = 1; i <= n; i++)scanf("%d", &a[i]);
memset(dp, -1, sizeof dp);
cout<<dfs(1, n)<<endl;
}
return 0;
}

POJ 1651 Multiplication Puzzle 区间dp(水的更多相关文章

  1. poj 1651 Multiplication Puzzle (区间dp)

    题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...

  2. POJ 1651 Multiplication Puzzle(类似矩阵连乘 区间dp)

    传送门:http://poj.org/problem?id=1651 Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K T ...

  3. POJ 1651 Multiplication Puzzle (区间DP)

    Description The multiplication puzzle is played with a row of cards, each containing a single positi ...

  4. Poj 1651 Multiplication Puzzle(区间dp)

    Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10010   Accepted: ...

  5. POJ 1651 Multiplication Puzzle (区间DP,经典)

    题意: 给出一个序列,共n个正整数,要求将区间[2,n-1]全部删去,只剩下a[1]和a[n],也就是一共需要删除n-2个数字,但是每次只能删除一个数字,且会获得该数字与其旁边两个数字的积的分数,问最 ...

  6. POJ1651:Multiplication Puzzle(区间DP)

    Description The multiplication puzzle is played with a row of cards, each containing a single positi ...

  7. poj 1651 Multiplication Puzzle【区间DP】

    题目链接:http://poj.org/problem? id=1651 题意:初使ans=0,每次消去一个值,位置在pos(pos!=1 && pos !=n) 同一时候ans+=a ...

  8. poj 1651 Multiplication Puzzle

    题目链接:http://poj.org/problem?id=1651 思路:除了头尾两个数不能取之外,要求把所有的数取完,每取一个数都要花费这个数与相邻两个数乘积的代价,需要这个代价是最小的 用dp ...

  9. POJ 1651 Mulitiplication Puzzle

    The multiplication puzzle is played with a row of cards, each containing a single positive integer. ...

随机推荐

  1. Jupyter IPython dead kernel and do not restart

    本人遇到的情况:dead kernel & try to restart failed 查看CMD发现这个库安装有问题 解决办法 1.pip uninstall backports.shuti ...

  2. 动态规划----最长公共子序列(C++实现)

    最长公共子序列 题目描述:给定两个字符串s1 s2 … sn和t1 t2 … tm .求出这两个字符串的最长公共子序列的长度.字符串s1 s2 … sn的子序列指可以表示为 … { i1 < i ...

  3. 洛谷——P1602 Sramoc问题

    P1602 Sramoc问题 $bfs$搜索 保证第一个搜到的符合条件的就是最小的 #include<bits/stdc++.h> #define N 110000 using names ...

  4. jupyter 教程

    官网: http://jupyter.org/

  5. cgi fastcgi php-cgi php-fpm

      参考: 摘至:http://www.cnblogs.com/thinksasa/p/4497567.html 详说fastcgi,php-fpm的区别:http://segmentfault.co ...

  6. Quartz Spring分布式集群搭建Demo

    注:关于单节点的Quartz使用在这里不做详细介绍,直接进阶为分布式集群版的 1.准备工作: 使用环境Spring4.3.5,Quartz2.2.3,持久化框架JDBCTemplate pom文件如下 ...

  7. Shader Wave

    Shader Wave 一.原理 1. 采用 UV 坐标为原始数据,生成每一条波浪线. 2. 使用 Unity 的 Time.y 作为时间增量,动态变换波形. 二.操作步骤 1. 首先使用纹理坐标生成 ...

  8. web环境搭建

    [服务器] 硬件设备---计算机 软件 [作用] 作为web服务器运行.可以管理web项目 [目录说明] bin :存放各类可以执行文件,如:startup.bat conf:存放各类配置文件,常用配 ...

  9. C51 独立按键 个人笔记

    独立按键类似于一个开关,按下时开关闭合 防抖 硬件防抖 软件防抖 通过延时,滤掉抖动的部分 电路图 普中科技的开发板,独立按键电路图如下 判断按键按下 因此判断是否按下开关的方法是看引脚是否为低电平( ...

  10. PHP读取mysql中的数据

    <!DOCTYPE HTML> <html> <head> <title> PHP动态读取mysql中的数据 </title> <me ...