博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZOJ 1602 Multiplication Puzzle(动态规划)
阅读量:4552 次
发布时间:2019-06-08

本文共 1544 字,大约阅读时间需要 5 分钟。

Multiplication Puzzle

Time Limit: 2 Seconds      
Memory Limit: 65536 KB

The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card out of the row and scores the number of points equal to the product of the number on the card taken and the numbers on the cards on the left and on the right of it. It is not allowed to take out the first and the last card in the row. After the final move, only two cards are left in the row.

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
The first line of the input file contains the number of cards N (3 <= N <= 100). The second line contains N integers in the range from 1 to 100, separated by spaces.

Process to the end of file.

Output
Output file must contain a single integer - the minimal score.

Sample Input
6
10 1 50 50 20 5

Sample Output
3650

 

矩阵连乘 动态规划

View Code
1 # include
2 # include
3 # define inf 0xffffff 4 int dp[110][110]; 5 int a[110]; 6 int i,j,t,r,tmp; 7 int n; 8 int main() 9 {10 while(scanf("%d",&n)!=EOF)11 {12 for(i=0; i

 

转载于:https://www.cnblogs.com/acm-bingzi/archive/2013/04/08/3008405.html

你可能感兴趣的文章
poj2417 bzoj3239 Discrete Logging(bsgs)
查看>>
UVa10054 - The Necklace(欧拉回路【输出带来的麻烦)
查看>>
string和stringbuffer的区别 集合的作用 ArrayList vector linklist hashmap hashtable collection和collections...
查看>>
6月27日 ajax
查看>>
iOS开发之画图板(贝塞尔曲线)
查看>>
4嵌入式作业io
查看>>
IntelliJ Idea编译报错:javacTask: 源发行版 1.7 需要目标发行版 1.7
查看>>
Cognos中新建SQLserver数据源的步骤
查看>>
HttpClient连接超时及读取超时
查看>>
SQL优化方法
查看>>
SEO必须掌握的高级搜索指令
查看>>
生产者消费者模型
查看>>
ORACLE 字符串超长问题解决方案
查看>>
使用ZooKeeper协调多台Web Server的定时任务处理(方案1)
查看>>
20171116 每周例行报告
查看>>
[C#] SHA1校验函数用法
查看>>
linux 下 VMware 提示Unable to change virtual machine power state:
查看>>
洛谷P1585 魔法阵
查看>>
线程 题待做
查看>>
PL/SQL可以连oracle,但是jdbc连不上 【转】
查看>>