题目链接: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>…
传送门: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…
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…
题意: 给出一个序列,共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]的任一子区…
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…
题目链接:http://poj.org/problem? id=1651 题意:初使ans=0,每次消去一个值,位置在pos(pos!=1 && pos !=n) 同一时候ans+=a[pos-1]*a[pos]*a[pos+1].一直消元素直到最后剩余2个,求方案最小的ans是多少? 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #…
题目链接:http://poj.org/problem?id=1651 思路:除了头尾两个数不能取之外,要求把所有的数取完,每取一个数都要花费这个数与相邻两个数乘积的代价,需要这个代价是最小的 用dp[i][j]表示区间[i,j]的最小代价,那么就有dp[i][j]=min(dp[i][k]+dp[k][j]+a[i]*a[k]*a[j]) i+1<=k<=j-1 #include<cstdio> #include<iostream> #include<algor…
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 numb…
POJ - 3280 Cheapest Palindrome Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u id=16272" class="login ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block;…
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…
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…
Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6033   Accepted: 3220 Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if s is a regular…
<题目链接> 题目大意: 一个由小写字母组成的字符串,给出字符的种类,以及字符串的长度,再给出添加每个字符和删除每个字符的代价,问你要使这个字符串变成回文串的最小代价. 解题分析: 一道区间DP的好题.因为本题字符串的长度最大为2e3,所以考虑$O(n^2)$直接枚举区间的两个端点,然后对枚举的区间进行状态转移,大体上有三种转移情况: $dp[l][r]$表示$[l,r]$为回文串的最小代价 对于区间$[l,r]$,当$str[l]==str[r]$时,$dp[l][r]=dp[l+1][r-…
Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if s is a regular brackets sequence, then (s) and [s] are regular brackets sequences, and if a and b are regul…
题意:给你一个字符串,请把字符串压缩的尽量短,并且输出最短的方案. 例如:AAAAA可压缩为5(A), NEERCYESYESYESNEERCYESYESYES可压缩为2(NEERC3(YES)). 思路:区间DP,设dp[i][j]是把区间[l, r]内的字符压缩之后的最短长度,那么可以想到区间[l, r]可以通过两种方式转换而来: 1 :[i, j]整个区间本来就可以被压缩 2 :由2个子区间合并而来. 第二种转换是区间DP的常见操作,第一种直接暴力枚举可重叠串的长度即可. 代码: #inc…
题意: 给出一个字符串,其中仅仅含 “ ( ) [ ] ” 这4钟符号,问最长的合法符号序列有多长?(必须合法的配对,不能混搭) 思路: 区间DP的常规问题吧,还是枚举区间[i->j]再枚举其中第k个与第i个来配对,如果配对了就+2这样子. //#include <bits/stdc++.h> #include <iostream> #include <cstdio> #include <cstring> #include <cmath>…
题目: 给出一个有括号的字符串,问这个字符串中能匹配的最长的子串的长度. 思路: 区间DP,首先枚举区间长度,然后在每一个长度中通过枚举这个区间的分割点来更新这个区间的最优解.还是做的少. 代码: //#include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <iostream> #define MAX 1000000000 #define FRE() freopen(&qu…
题意 : 给出一个由 n 中字母组成的长度为 m 的串,给出 n 种字母添加和删除花费的代价,求让给出的串变成回文串的代价. 分析 :  原始模型 ==> 题意和本题差不多,有添和删但是并无代价之分,要求最少操作几次才能是其变成回文串 ① 其实细想之后就会发现如果没有代价之分的话删除和增添其实是一样的,那么除了原串原本拥有的最长回文串不用进行考虑处理,其他都需要进行删除或者增添来使得原串变成回文串,所以只要对原串 S 和其反向串 S' 找出两者的最长公共子串长度 L 再用总长减去 L 即可 ②…
Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if s is a regular brackets sequence, then (s) and [s] are regular brackets sequences, and if a and b are regul…
题目链接:http://poj.org/problem?id=1141 题解:求已知子串最短的括号完备的全序列 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define ll long long ; const int INF=0x3f3f3f3f; ][]; ][]; ]; int Find(int x…
题目链接: 黑书 P116 HDU 2157 棋盘分割 POJ 1191 棋盘分割 分析:  枚举所有可能的切割方法. 但如果用递归的方法要加上记忆搜索, 不能会超时... 代码: #include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; const int inf=6400*6400; const int N=8; int sum[1…
题目链接:http://poj.org/problem?id=1088 思路分析: 1>状态定义:状态dp[i][j]表示在位置map[i][j]可以滑雪的最长区域长度: 2>状态转移方程:由于由位置[i, j]只能向四个方向移动,所以子问题最多有四个:所以dp[i][j]为其邻域可以滑雪的最大区域长度加上从该位置滑到邻域的长度,即1: 代码如下: #include <cstdio> #include <iostream> #include <algorithm&…
题目链接:http://poj.org/problem?id=2192 思路分析:该问题可以看做dp问题,同时也可以使用dfs搜索求解,这里使用dp解法: 设字符串StrA[0, 1, …, n]和StrB[0,1, .., m]构成字符串Str[0, 1, … , m + n + 1]; 1)状态定义:dp[i, j]表示字符串StrA[0, 1, …, i-1]和字符串StrB[0, 1, .., j-1]构成字符串Str[0, 1, …, i+j-1]: 2)状态转移:如果dp[i-1][…
题目链接:http://poj.org/problem?id=3624 思路分析: 经典的0-1背包问题: 分析如下: 代码如下: #include <iostream> using namespace std; + ; int dp[MAX_N], W[MAX_N], D[MAX_N]; int Max( int a, int b ) { return a > b ? a : b; } int main() { int n, m; memset( dp, , sizeof(dp) );…
题目链接:http://poj.org/problem?id=1458 思路分析:经典的最长公共子序列问题(longest-common-subsequence proble),使用动态规划解题. 1)问题定义:给定两个序列X=<X1, X2, ...., Xm>和Y = <Y1, Y2, ...., Yn>,要求求出X和Y长度最长的最长公共子序列: 2)问题分析: <1>动态规划问题都是多阶段决策最优化问题:在这些问题中,问题可以被划分为多个阶段,每个阶段都需要作出一…
题目链接:http://poj.org/problem?id=2346 思路分析:使用动态规划解法:设函数 d( n, x )代表长度为n且满足左边n/2位的和减去右边n/2位的和为x的数的数目. 将一个长度为n的数看做n个数字 A1, A2....An ( 0 <= Ai <= 9  ),将字符分为两个集合{ A1, A2....An/2 } 与 { An/2+1.....An }; 问题转换为求集合中元素和相等的数目.先从每个集合中选出一个元素,求它们差为a的可能数目,即d( 2, a )…
题目链接:http://poj.org/problem?id=3176 思路分析:基本的DP题目:将每个节点视为一个状态,记为B[i][j], 状态转移方程为 B[i][j] = A[i][j] + Max( B[i+1][j], B[i+1][j+1] ); 代码如下: #include <stdio.h> + ; int A[MAX_N][MAX_N], B[MAX_N][MAX_N]; int Max( int a, int b ) { return a > b ? a : b;…
题目链接:http://poj.org/problem?id=3280 Time Limit: 2000MS Memory Limit: 65536K Description Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID tag that th…