区间dp-zoj3541-The Last Puzzle】的更多相关文章

Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10010   Accepted: 6188 Description The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one…
传送门: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 intege…
ZOJ 3541 题目大意:有n个按钮,第i个按钮在按下ti 时间后回自动弹起,每个开关的位置是di,问什么策略按开关可以使所有的开关同时处于按下状态 Description There is one last gate between the hero and the dragon. But opening the gate isn't an easy task. There were n buttons list in a straight line in front of the gate…
E - Multiplication Puzzle  POJ - 1651 这个题目没有特别简单,但是也没有我想象之中的那么难,这个题目时区间dp,因为我们是要对区间进行考虑的. 但是呢,这个也和动态规划的基本原理息息相关. 动态规划 我们一般需要去找这个的子问题,这个题目因为左端点和右端点是不能动 的,所以最后一个取走的就是a[l]*a[k]*a[r] 所以说这个题目的子问题就是每次去找一个区间,然后记录区间的左右端点,然后再找这个区间乘法最小和. dp[i][k]=min(dp[i][k],…
比较好做的区间DP 状态转移方程:DP[i][j] 表示区间[i,j]最小的乘积和. DP[i][j] = MIN{DP[i][k-1]+DP[k+1][j] + a[k]*a[i-1]*a[j+1] | i<k<j}; 最后结果就是DP[2][N-1] #include <map> #include <set> #include <stack> #include <queue> #include <cmath> #include &…
题意:n个数字的串,每取出一个数字的代价为该数字和左右的乘积(1.n不能取),问最小代价 思路:dp[i][j]表示把i~j取到只剩 i.j 的最小代价. 代码: #include<set> #include<map> #include<cmath> #include<queue> #include<cstdio> #include<cstring> #include<algorithm> typedef long lon…
题意: 给出一个序列,共n个正整数,要求将区间[2,n-1]全部删去,只剩下a[1]和a[n],也就是一共需要删除n-2个数字,但是每次只能删除一个数字,且会获得该数字与其旁边两个数字的积的分数,问最少可以获得多少分数? 思路: 类似于矩阵连乘的问题,用区间DP来做. 假设已知区间[i,k-1]和[k+1,j]各自完成删除所获得的最少分数,那么a[k]是区间a[i,j]内唯一剩下的一个数,那么删除该数字就会获得a[k]*a[i-1]*a[i+1]的分数了.在枚举k的时候要保证[i,j]的任一子区…
http://poj.org/problem?id=1651 题意:给出n个数字,每取中间一个数,就会使得权值加上中间这个数和两边的乘积,求取剩两个数最少的权值是多少. 思路:区间dp. 一开始想了挺久还是写不出方程,做了点别的事回来再想就突然觉得很简单了. 一开始使得长度为1和2的区间dp[i][j]为0. 然后dp[i][j] = min(dp[i][k] + dp[k][j] + w[k] * w[i] * w[j]). 枚举的k为中间拿掉的数,然后和左右的区间和相加就是最后答案了. #i…
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University,You are facing the main building of Northeastern University.…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University,You are facing the main building of Northeastern Universi…