传送门:http://poj.org/problem?id=1651

Multiplication Puzzle
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13109   Accepted: 8034

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.

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

  1. 6
  2. 10 1 50 50 20 5

Sample Output

  1. 3650

Source

Northeastern Europe 2001, Far-Eastern Subregion
 
题目意思:
给你一串数字,头尾不能动,每次取出一个数字,这个数字贡献=该数字与左右相邻数字的乘积,求一个最小值。
分析:
是一个区间dp问题,类似矩阵连乘的做法,也是需要在一个区间中选择一个k值从而来达到你的某种要求,这里是要使得消去的值最小
概况一下题意就是:
初使ans=0,每次消去一个值,位置在pos(pos!=1 && pos !=n)
同时ans+=a[pos-1]*a[pos]*a[pos+1],一直消元素直到最后剩余2个,求方案最小的ans是多少?
  1. #include <iostream>
  2. #include<algorithm>
  3. #include <cstdio>
  4. #include<cstring>
  5. using namespace std;
  6. #define max_v 105
  7. #define INF 9999999
  8. int a[max_v];
  9. int dp[max_v][max_v];
  10. int main()
  11. {
  12. int n;
  13. while(~scanf("%d",&n))
  14. {
  15. for(int i=;i<=n;i++)
  16. {
  17. scanf("%d",&a[i]);
  18. }
  19. memset(dp,,sizeof(dp));
  20. for(int r=;r<n;r++)
  21. {
  22. for(int i=;i<=n-r+;i++)
  23. {
  24. int j=i+r-;
  25. int t=INF;
  26. for(int k=i;k<=j-;k++)
  27. {
  28. t=min(t,dp[i][k]+dp[k+][j]+a[i-]*a[k]*a[j]);
  29. }
  30. dp[i][j]=t;
  31. }
  32. }
  33. printf("%d\n",dp[][n]);
  34. }
  35. return ;
  36. }
 

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)

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

  3. Poj 1651 Multiplication Puzzle(区间dp)

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

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

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

  5. poj 1651 Multiplication Puzzle

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

  6. poj 1651 Multiplication Puzzle【区间DP】

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

  7. POJ 1651 Multiplication Puzzle 区间dp(水

    题目链接:id=1651">点击打开链 题意: 给定一个数组,每次能够选择内部的一个数 i 消除,获得的价值就是 a[i-1] * a[i] * a[i+1] 问最小价值 思路: dp ...

  8. POJ1651 Multiplication Puzzle —— DP 最优矩阵链乘 区间DP

    题目链接:https://vjudge.net/problem/POJ-1651 Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65 ...

  9. POJ 1651 Mulitiplication Puzzle

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

随机推荐

  1. JavaScript之parseInt()数值转换常被忽略的问题

    使用parseInt()你可以从字符串中获取数值,该方法接受另一个基数参数,这经常省略,但不应该.当字符串以”0″开头的时候就有可能会出问题,例如,部分时间进入表单域,在ECMAScript 3中,开 ...

  2. 固态硬盘SSD与闪存(Flash Memory)

    转自:http://qiaodahai.com/solid-state-drives-ssd-and-flash-memory.html 固态硬盘SSD(Solid State Drive)泛指使用N ...

  3. 无法解析 id,或者它不是字段

    解决方法:首先,看下R文件,有没有你上面的ID.没有的话,点项目-clean . 有的话,估计你是导了android里面的那个R包了,你看看你导的包有木有 “import android.R”有的话去 ...

  4. Object.preventExtensions()使用技巧

    Object.preventExtensions() 方法让一个对象变的不可扩展,也就是永远不能再添加新的属性. // Object.preventExtensions将原对象变的不可扩展,并且返回原 ...

  5. NOI.AC NOIP模拟赛R3解题报告

    心路历程 预计得分:\(100+100+50=250\) 实际得分:\(10 +100 +50 = 160\) 三道原题,真好.T2做过,T1写了个错误思路,T3写了写50分状压dp. 整场考试实际在 ...

  6. SQLServer导入大sql文件报错 对 COM 组件的调用返回了错误 HRESULT E_FAIL。 (mscorlib)

    打开cmd执行(d:\script.sql为sql文件位置):  sqlcmd -S 127.0.0.1 -U sa -P sa -i d:\script.sql    From:https://ww ...

  7. Spring boot 使用WebAsyncTask处理异步任务

    上文介绍了基于 @Async 注解的 异步调用编程,本文将继续引入 Spring Boot 的 WebAsyncTask 进行更灵活异步任务处理,包括 异步回调,超时处理 和 异常处理. 正文 1. ...

  8. RC4 加解密

    加密解密都是这一个接口 int Rc4EncryptFile(std::string in_file_path, std::string out_file_path, const char *rc4_ ...

  9. SQL点点滴滴_唯一索引设计指南-转载

    唯一索引能够保证索引键中不包含重复的值, 从而使表中的每一行从某种方式上具有唯一性, 只有当唯一性是数据本身的特征时, 指定唯一索引才有意义. 例如, 如果您希望确保 HumanResources.E ...

  10. ipsec验证xl2tpd报错:handle_packet: bad control packet!

    使用ipsec和xl2tpd搭建好vpn后,使用ipsec密钥方式不能连接,显示 “连接的时候被远程服务器中止” 使用xl2tpd -D查看连接情况,尝试连接了许多次,错误如下: 开始不确定问题所在, ...