poj 1651 Multiplication Puzzle (区间dp)
题目链接:http://poj.org/problem?id=1651
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
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<cstring>
- using namespace std;
- #define ll long long
- const int maxn=1e2+;
- const int INF=0x3f3f3f3f;
- int dp[][];
- int a[];
- int main()
- {
- int n;
- while(scanf("%d",&n)==)
- {
- memset(dp,,sizeof(dp));
- for(int i=; i<=n; i++) scanf("%d",&a[i]);
- for(int d=; d<n; d++)
- for(int i=; i+d<=n; i++){
- int j=i+d;
- dp[i][j]=INF;
- for(int k=i+; k<j; k++)
- dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]+a[k]*a[i]*a[j]);
- }
- printf("%d\n",dp[][n]);
- }
- return ;
- }
poj 1651 Multiplication Puzzle (区间dp)的更多相关文章
- POJ 1651 Multiplication Puzzle 区间dp(水
题目链接:id=1651">点击打开链 题意: 给定一个数组,每次能够选择内部的一个数 i 消除,获得的价值就是 a[i-1] * a[i] * a[i+1] 问最小价值 思路: dp ...
- POJ 1651 Multiplication Puzzle(类似矩阵连乘 区间dp)
传送门:http://poj.org/problem?id=1651 Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K T ...
- 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个数字,但是每次只能删除一个数字,且会获得该数字与其旁边两个数字的积的分数,问最 ...
- POJ1651:Multiplication Puzzle(区间DP)
Description The multiplication puzzle is played with a row of cards, each containing a single positi ...
- poj 1651 Multiplication Puzzle【区间DP】
题目链接:http://poj.org/problem? id=1651 题意:初使ans=0,每次消去一个值,位置在pos(pos!=1 && pos !=n) 同一时候ans+=a ...
- poj 1651 Multiplication Puzzle
题目链接:http://poj.org/problem?id=1651 思路:除了头尾两个数不能取之外,要求把所有的数取完,每取一个数都要花费这个数与相邻两个数乘积的代价,需要这个代价是最小的 用dp ...
- POJ 1651 Mulitiplication Puzzle
The multiplication puzzle is played with a row of cards, each containing a single positive integer. ...
随机推荐
- linux查看系统版本和系统位数
1. uname -a you will view kernel name.network node hostname.kernel release.kernel version.machine h ...
- 【python】类中的self
在python的类中,经常会写self,代表对象自己.如下例: #coding=utf-8 class Foo: def __init__(self, name): self.name = name ...
- shared_ptr 和 unique_ptr
c++11标准废除乐auto_ptr, C++ 标准库智能指针 使用这些智能指针作为将指针封装为纯旧 C++ 对象 (POCO) 的首选项. unique_ptr 只允许基础指针的一个所有者. 除非你 ...
- Ionic2 Tutorial
build your first app Now that you have Ionic and its dependencies installed, you can build your firs ...
- 有关struts2中用到 js 总结
1.js中取Struts2中的栈里的值 var current = "${currentPage}"; 2.js 如何提交执行提交url连接 ,以及 Struts中的url如何如何 ...
- 浅谈我的编程之路——感谢引领我的leader
在开发的道路上,就始终无法避开版本控制,哪怕你是独自一人进行开发,版本控制也是有必要的,从最早开始使用CVS,到后来使用SVN,再到git,最后又回到了SVN,但是不知道为什么真的对SVN很无爱. 现 ...
- sp_who使用
[SQL Server] sp_who, sp_who2和sp_who3 sp_who可以返回如下信息: (可选参数LoginName, 或active代表活动会话数)Spid (系 ...
- MVC – 6.控制器 Action方法参数与返回值
6.1 Controller接收浏览器数据 a.获取Get数据 : a1:获取路由url中配置好的制定参数: 如配置好的路由: 浏览器请求路径为: /User/Modify/1 ,MVC框架获 ...
- MySQL replace函数替换字符串语句的用法(mysql字符串替换)
MySQL replace函数我们经常用到,下面就为您详细介绍MySQL replace函数的用法,希望对您学习MySQL replace函数方面能有所启迪. 最近在研究CMS,在数据转换的时候需要用 ...
- C# virtual override 和 new 的区别
一直以来我都对 virtual override 和 new 之间的区别感到疑惑不解. 特别笔试的时候特别容易考到,真的很容易弄错啊,畜生! 光看理论永远记不住,那不如写几行代码就懂了. 首先看看v ...