POJ 1651 Multiplication Puzzle(类似矩阵连乘 区间dp)
传送门:http://poj.org/problem?id=1651
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 13109 | Accepted: 8034 |
Description
The goal is to take cards in such order as to minimize the total number of scored points.
For example, if cards in the row contain numbers 10 1 50 20 5, player might take a card with 1, then 20 and 50, scoring
10*1*50 + 50*20*5 + 10*50*5 = 500+5000+2500 = 8000
If he would take the cards in the opposite order, i.e. 50, then 20, then 1, the score would be
1*50*20 + 1*20*5 + 10*1*5 = 1000+100+50 = 1150.
Input
Output
Sample Input
6
10 1 50 50 20 5
Sample Output
3650
Source
同时ans+=a[pos-1]*a[pos]*a[pos+1],一直消元素直到最后剩余2个,求方案最小的ans是多少?
#include <iostream>
#include<algorithm>
#include <cstdio>
#include<cstring>
using namespace std;
#define max_v 105
#define INF 9999999
int a[max_v];
int dp[max_v][max_v];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
memset(dp,,sizeof(dp));
for(int r=;r<n;r++)
{
for(int i=;i<=n-r+;i++)
{
int j=i+r-;
int t=INF;
for(int k=i;k<=j-;k++)
{
t=min(t,dp[i][k]+dp[k+][j]+a[i-]*a[k]*a[j]);
}
dp[i][j]=t;
}
}
printf("%d\n",dp[][n]);
}
return ;
}
POJ 1651 Multiplication Puzzle(类似矩阵连乘 区间dp)的更多相关文章
- poj 1651 Multiplication Puzzle (区间dp)
题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...
- POJ 1651 Multiplication Puzzle (区间DP)
Description The multiplication puzzle is played with a row of cards, each containing a single positi ...
- Poj 1651 Multiplication Puzzle(区间dp)
Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10010 Accepted: ...
- POJ 1651 Multiplication Puzzle (区间DP,经典)
题意: 给出一个序列,共n个正整数,要求将区间[2,n-1]全部删去,只剩下a[1]和a[n],也就是一共需要删除n-2个数字,但是每次只能删除一个数字,且会获得该数字与其旁边两个数字的积的分数,问最 ...
- poj 1651 Multiplication Puzzle
题目链接:http://poj.org/problem?id=1651 思路:除了头尾两个数不能取之外,要求把所有的数取完,每取一个数都要花费这个数与相邻两个数乘积的代价,需要这个代价是最小的 用dp ...
- poj 1651 Multiplication Puzzle【区间DP】
题目链接:http://poj.org/problem? id=1651 题意:初使ans=0,每次消去一个值,位置在pos(pos!=1 && pos !=n) 同一时候ans+=a ...
- POJ 1651 Multiplication Puzzle 区间dp(水
题目链接:id=1651">点击打开链 题意: 给定一个数组,每次能够选择内部的一个数 i 消除,获得的价值就是 a[i-1] * a[i] * a[i+1] 问最小价值 思路: dp ...
- POJ1651 Multiplication Puzzle —— DP 最优矩阵链乘 区间DP
题目链接:https://vjudge.net/problem/POJ-1651 Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65 ...
- POJ 1651 Mulitiplication Puzzle
The multiplication puzzle is played with a row of cards, each containing a single positive integer. ...
随机推荐
- spring历史和哲学
spring 历史: 2004年 Spring Framework 1.0 final 正式问世. 1.在Spring1.x时代,都是通过xml文件配置bean,随着项目的不断扩大,需要将xml配置分 ...
- Oracle OCI操作UDT相关学习
1.Oracle数据类型 Oracle的数据类型如下 字符串类型 char nchar varchar2 nvarchar2 数值类型 int number integer smallint 日期类型 ...
- MySql数据快速导入
使用LOAD DATA INFILE 插入速度可以提升很多 左侧是直接导入100W花费135s ,Dos界面通过Load方式导入450W只用时23s,性能一下子显示出来了.
- Python入门-迭代器
在说迭代器之前,首先来简单说一下函数名的运用以及闭包的概念和应用,有助于我们理解以后的知识. 一.函数名的运用 函数名是一个变量,但它是一个特殊的变量,与括号配合可以执行函数的变量. 1.函数名的内存 ...
- ubuntu终端颜色设置
在 .bashrc中增加 PS1='${debian_chroot:+($debian_chroot)}\[\033[00;32m\]\u @ \h\[\033[00m\]:\[\033[00;34m ...
- 使用electron构建跨平台Node.js桌面应用
最近,把团队内经常使用的一个基于Node.js制作的小工具给做成了可视化操作的桌面软件,使用的是electron,这里简单分享一下使用electron的一些经验和心得. 一.如何使用electron把 ...
- hdu 3367 Pseudoforest (最大生成树 最多存在一个环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3367 Pseudoforest Time Limit: 10000/5000 MS (Java/Oth ...
- 04_dubbo_ioc
[dubbo的IOC实现方法] dubbo的IOC具体实现在:T injectExtension( T instance )方法中,该方法在3个地方被使用: ExtensionLoader.getEx ...
- Android Button事件处理
一般只需要处理按钮的点击事件就可以,但想让一个按钮处理多个事件,就得同时监听多个方法. OnClickListener 点击事件 OnLongClickListener 长按事件 OnTouchLi ...
- 微软在Build 2016开发者大会中发布 “认知服务”,牛津计划有正式名字啦!
2016年3月30日:微软在Build 2016开发者大会中发布“认知服务”. 在Build 2016开发者大会中,微软发布了新的智能服务:微软认知服务(Microsoft Cognitive Ser ...