题意: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…
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…
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…
题目链接:http://poj.org/problem?id=1651 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 prod…
题目链接:id=1651">点击打开链 题意: 给定一个数组,每次能够选择内部的一个数 i 消除,获得的价值就是 a[i-1] * a[i] * a[i+1] 问最小价值 思路: dp[l,r] = min( dp[l, i] + dp[i, r] + a[l] * a[i] * a[r]); #include <cstdio> #include <iostream> #include <algorithm> #include <queue>…
这道题我不会,看了网上的题解才会的,涨了姿势,现阶段还是感觉区间DP比较难,主要是太弱...QAQ 思路中其实有贪心的意思,n个住户加一个商店,分布在一维直线上,应该是从商店开始,先向两边距离近的送,再往远的送. 这样肯定省时间,因为去了远的地方,近的地方自然就送了,不可能回来再送,所以我们可以开始定义状态 dp[i][j]代表送完从 i 到 j 所耗费的最小代价,但是我们发现此时状态虽然有了但是很难写出状态转移方程, 因为送完 i 到 j ,最后要么停在 i ,要么停在 j ,所以定义dp[i…
Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8737   Accepted: 5468 Description The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one…
题意 t组数据,每组数据有n个方块,给出它们的颜色,每次消去的得分为相同颜色块个数的平方(要求连续),求最大得分. 首先看到这题我们发现我们要把大块尽可能放在一起才会有最大收益,我们要将相同颜色块合在一起,我们可以分区间进行处理,便可用区间dp解决,我们尝试合并区间我们定义状态f[i][j]表示合并i-j这个区间的最大得分,那么状态转移方程便可写为 f[i][j]=max(f[i][j],f[i][u]+f[v][j]+(v-u+1)^2)(i=<u,v<=j) 我们可以发现我们这样去做不一定…
When we are focusing on solving problems, we usually prefer to stay in front of computers rather than go out for lunch. At this time, we may call for food delivery. Suppose there are N people living in a straight street that is just lies on an X-coor…
Time Limit: 2 Seconds      Memory Limit: 65536 KB When we are focusing on solving problems, we usually prefer to stay in front of computers rather than go out for lunch. At this time, we may call for food delivery. Suppose there are N people living i…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4255 题目大意:在x轴上有n个客人,每个客人每分钟增加的愤怒值不同.给出客人和餐厅的位置,以及客人每分钟增加的愤怒值,和送餐行走一公里需要的时间,问送完n个客人的外卖最小愤怒值.解题思路:如果要访问完[i,j],那么它的子区间一定访问完了.用dp[i][j][0]表示访问完区间[i,j]并留在左端点,dp[i][j][1]表示访问完区间[i,j]并留在右端点.把饭店…
Description You want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut the cake into several triangle-shaped parts for the invited comers. You have a knife to cut. The trace of each cut is a line segment, whose two endpoin…
题意: 给出平面直角坐标系上的n个点的坐标,表示一个多边形蛋糕,先判断是否是凸多边形,若否,输出"I can't cut.".若是,则对这个蛋糕进行3角形剖分,切n-3次变成n-2份三角形蛋糕给小伙伴吃,但是每切一次需要一个费用,公式是:cost[i][j] = |xi + xj| * |yi + yj| % p 表示在两点i和j之间切一刀的费用.问最少费用是多少? 思路: 判断是否凸多边形需要用到求凸包的Andrew算法,时间复杂度为O(nlogn),然后判断凸包内的点数是否为n就行…
#include "Head.cpp" const int N = 10007; int n, m; struct Point{ int x,y; bool operator < (const Point &com) const{ if(y != com.y) return y < com.y; return x < com.x; } }a[N]; int cost[N][N]; int f[N][N]; Point sta[407],tmp[407]; in…
也写了好几天的区间DP了,这里稍微总结一下(感觉还是不怎么会啊!). 但是多多少少也有了点感悟: 一.在有了一点思路之后,一定要先确定好dp数组的含义,不要模糊不清地就去写状态转移方程. 二.还么想好...想到了再加上去.... 之前也看了别人的总结,也给出了不少区间DP的模板.这里我也贴一下基本的模板: 区间DP模板 ; len < n; len++) { //操作区间的长度 ; i+len <= n; i++) { //始末 int j=i+len; //检查是否匹配(非必须) for (…
Multiplication Puzzle ZOJ - 1602 传送门 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…
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…
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…
题目链接:https://vjudge.net/problem/POJ-1651 Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11239   Accepted: 6980 Description The multiplication puzzle is played with a row of cards, each containing a single positive…
传送门: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…
Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9419 Accepted: 5850 Description The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card…
E - Multiplication Puzzle  POJ - 1651 这个题目没有特别简单,但是也没有我想象之中的那么难,这个题目时区间dp,因为我们是要对区间进行考虑的. 但是呢,这个也和动态规划的基本原理息息相关. 动态规划 我们一般需要去找这个的子问题,这个题目因为左端点和右端点是不能动 的,所以最后一个取走的就是a[l]*a[k]*a[r] 所以说这个题目的子问题就是每次去找一个区间,然后记录区间的左右端点,然后再找这个区间乘法最小和. dp[i][k]=min(dp[i][k],…
题意: 给出一个序列,共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…
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…
Prelude 快THUWC了,所以补一下以前的题. 真的是一道神题啊,网上的题解没几篇,而且还都看不懂,我做了一天才做出来. 传送到LOJ:(>人<:) Solution 直接切入正题. 我们考虑区间dp,第一件事是离散化. 然后用\(g(i,j)\)表示消除完闭区间\([i,j]\)的最小费用. 然后呢?怎么转移?exm??? 这时候会有一个非常自然的想法. 计算\(g(i,j)\)的时候,我们枚举两个数\(l,r\),然后保留下值在闭区间\([l,r]\)之内的所有数,先消除掉其他的数字…
题目链接 https://www.luogu.org/problemnew/show/P1005 分析 忽然发现这篇题解好像并没有什么意义...因为跟奶牛零食那道题一模一样,博主比较懒如果您想看题解的话去区间DP标签中找奶牛零食那道题吧,实在抱歉... 话说NOIP喜欢考奶牛题啊(e.g. NOIP2017 D1T1),USACO刷完是不是就能阿克了呀 代码没写高精用__int128代替,话说什么时候补个高精的坑(flag) 代码 #include <cstdio> #include <…
Blocks题解 区间dp 阅读体验...https://zybuluo.com/Junlier/note/1289712 很好的一道区间dp的题目(别问我怎么想到的) dp状态 其实这个题最难的地方是这道题目的状态怎么设 首先既然是区间dp,那肯定最先想到的状态是 \(dp[i][j]\)表示消掉区间\([i,j]\)上所有的块的最大分数 突然发现这个状态会受区间外和\(i\)或\(j\)颜色相同的块的影响 并且转移也并不好转移=_= 所以我们考虑换一种状态... 既然说会受到外面的块的影响?…
Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7118   Accepted: 4385 Description The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one…
比较好做的区间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 &…