动态规划之Multiplication Puzzle
来源:互联网 发布:数据相关的问题 编辑:程序博客网 时间:2024/06/06 00:56
题目:
Description
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.
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
If he would take the cards in the opposite order, i.e. 50, then 20, then 1, the score would be
Input
The first line of the input 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.
Output
Output must contain a single integer - the minimal score.
Sample Input
6
10 1 50 50 20 5
Sample Output
3650
直接上代码:
#include<stdio.h>int num[100];int ans[100][100];int main(){ int N,i,len,tmp,k; scanf("%d",&N); for(i=0;i<N;i++) scanf("%d",&num[i]); for(len=2;len<N;len++){ for(i=0;i+len<N;i++){ for(k=i+1;k<i+len;k++){ tmp=num[i]*num[i+len]*num[k]+ans[i][k]+ans[k][i+len]; if(tmp<ans[i][i+len]||ans[i][i+len]==0) ans[i][i+len]=tmp; } } } printf("%d\n",ans[0][N-1]); return 0;}
0 0
- 动态规划之Multiplication Puzzle
- Multiplication Puzzle--动态规划
- 动态规划 Multiplication Puzzle poj 1651
- 动态规划——Multiplication Puzzle
- 动态规划之划分动态规划:矩阵链乘 poj 1651 Multiplication Puzzle
- POJ 1651 Multiplication Puzzle 动态规划及搜索
- 动态规划——Poj 1651 Multiplication Puzzle
- 【动态规划DP,二维动归】poj1651,Multiplication Puzzle
- poj 1651 Multiplication Puzzle -- (动态规划,区间dp)
- 最优矩阵链乘(动态规划dp)POJ 1651 Multiplication Puzzle
- multiplication puzzle
- Multiplication Puzzle
- Multiplication Puzzle
- Multiplication Puzzle
- [动态规划]UVA348 - Optimal Array Multiplication Sequence
- zoj1276Optimal Array Multiplication Sequence 动态规划
- POJ1651Multiplication Puzzle题解动态规划DP
- 动态规划 (Dynamic Programming) 之 矩阵链乘法(Matrix Chain Multiplication)
- Hibernate持久化对象的状态及状态之间的转换
- 虚方法
- API集合框架-LinkedList
- 2016郑州大学ACM/ICPC训练赛 B 追踪术
- Git Workflow工作流示意图
- 动态规划之Multiplication Puzzle
- JAVA Exception Handing
- java泛型(二)、泛型的内部原理:类型擦除以及类型擦除带来的问题
- 增加多层标签数量
- 我们就这样匆匆忙忙的赚了几亿美金
- hdoj 2028 Lowest Common Multiple Plus (最小公倍数,最大公约数)
- 207. Course Schedule 图的dfs算法
- 广播接收者Broadcast Receiver
- mysql 新增用户并设置权限