poj1390 2010.8.1
来源:互联网 发布:linux查看crontab任务 编辑:程序博客网 时间:2024/05/18 16:17
Blocks
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 1916 Accepted: 734
Description
Some of you may have played a game called'Blocks'. There are n blocks in a row, each box has a color. Here is anexample: Gold, Silver, Silver, Silver, Silver, Bronze, Bronze, Bronze, Gold.
The corresponding picture will be as shownbelow:
Figure 1
If some adjacent boxes are all of the samecolor, and both the box to its left(if it exists) and its right(if it exists)are of some other color, we call it a 'box segment'. There are 4 box segments.That is: gold, silver, bronze, gold. There are 1, 4, 3, 1 box(es) in thesegments respectively.
Every time, you can click a box, then thewhole segment containing that box DISAPPEARS. If that segment is composed of kboxes, you will get k*k points. for example, if you click on a silver box, thesilver segment disappears, you got 4*4=16 points.
Now let's look at the picture below:
Figure 2
The first one is OPTIMAL.
Find the highest score you can get, givenan initial state of this game.
Input
The first line contains the number of testst(1<=t<=15). Each case contains two lines. The first line contains aninteger n(1<=n<=200), the number of boxes. The second line contains nintegers, representing the colors of each box. The integers are in the range1~n.
Output
For each test case, print the case numberand the highest possible score.
Sample Input
2
9
1 2 2 2 2 3 3 3 1
1
1
Sample Output
Case 1: 29
Case 2: 1
Source
Liu Rujia@POJ
详见刘汝佳的黑书。。我好像隐隐约约知道什么叫记忆化搜索了。。。。。。
Source Code
Problem: 1390 User: creamxcream
Memory: 36416K Time: 1579MS
Language: C++ Result: Accepted
Source Code
#include <cstdio>#include <cstring>#define MAXN 210#define INF -1int color[MAXN],len[MAXN];int n,num;int f[MAXN][MAXN][MAXN];void init(){ memset(f,-1,sizeof(f)); scanf("%d",&n); int temp; scanf("%d",&temp); color[1]=temp; len[1]=1; num=1; for(int i=2;i<=n;i++) { scanf("%d",&temp); if (temp==color[num]) len[num]++; else { num++; color[num]=temp; len[num]=1; } }}int dpit(int i,int j,int k){ if (f[i][j][k]!=-1) return f[i][j][k]; if (i==j+1) return 0; int ans=INF; int temp=dpit(i,j-1,0)+(len[j]+k)*(len[j]+k); if (temp>ans) ans=temp; for(int p=i;p<j;p++) if (color[p]==color[j]) { temp=dpit(i,p,len[j]+k)+dpit(p+1,j-1,0); if (temp>ans) ans=temp; } f[i][j][k]=ans; return ans;}int main(){ int t; scanf("%d",&t); for (int i=1;i<=t;i++) { init(); int ans=dpit(1,num,0); printf("Case %d: %d\n",i,ans); } return 0;}
- poj1390 2010.8.1
- poj1390 2010.8.2
- poj1390
- poj1390
- poj1390 Blocks
- poj1390 Blocks
- poj1390 方块消除 dp
- poj1390-dp消方块
- POJ1390 Blocks 【动态规划】
- poj1390解题报告
- POJ1390 Blocks 区间DP
- [POJ1390]Blocks(dp)
- poj1390 Blocks(区间dp)
- poj1390 (区间dp)
- [POJ1390]Blocks(方块消除)
- [POJ1390]Blocks(区间dp)
- poj1390区间dp+记忆化搜索
- 网络日志(2010.8.1)
- poj1191 2010.7.31
- 318. Maximum Product of Word Lengths LeetCode
- 144. Binary Tree Preorder Traversal LeetCode
- 《Storm入门》中文版
- leetcode(153 154) FindMinimuminRotatedSortedArray与FindMinimuminRotatedSortedArray II
- poj1390 2010.8.1
- 94. Binary Tree Inorder Traversal LeetCode
- 不容易系列之(3)—— LELE的RPG难题
- poj2231 2010.8.1
- POJ 2771 Guardian of Decency(二分图最大独立集)
- 1026. 程序运行时间
- NYOJ-71-独木舟上的旅行
- uva10617 2010.8.1
- 145. Binary Tree Postorder Traversal LeetCode