Uva 10559 & POJ 1390 Blocks 区间dp
2014-04-22 16:05
411 查看
题意:
给定n个方块,相邻同色的方块可以消除,得分为消除的个数^2
问最高得分
dp[ l ][ r ][ k ] : 表示[l,r]区间内,消掉 [l,r)区间最高分 + 消掉[r, r+k] ([r,r+k]为同色)的最高分
给定n个方块,相邻同色的方块可以消除,得分为消除的个数^2
问最高得分
dp[ l ][ r ][ k ] : 表示[l,r]区间内,消掉 [l,r)区间最高分 + 消掉[r, r+k] ([r,r+k]为同色)的最高分
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<map> #include<queue> #include<stack> #include<set> #include<cmath> #include<vector> using namespace std; #define ll int #define N 210 ll dp ;//dp[l][r][k] 使得区间[l,r]为空时最高分 最后一次操作为将[r,r+k]个与r同色的块消掉 ll clo , n; ll dfs(ll l, ll r, ll k){ if(l>r)return 0; if(dp[l][r][k])return dp[l][r][k]; int ans = dfs(l,r-1,0) + (1+k)*(1+k); for(int i = r-1; i >= l; i--) if(clo[i] == clo[r]) ans = max(ans, dfs(l, i, k+1)+dfs(i+1,r-1,0)); return dp[l][r][k] = ans; } int main() { ll i, j, k, u, v, T, Cas = 1;scanf("%d",&T); while(T--){ scanf("%d",&n); memset(clo, -1, sizeof clo); for(i = 1; i <= n; i++) scanf("%d",&clo[i]); memset(dp, 0, sizeof dp); printf("Case %d: %d\n",Cas++, dfs(1,n,0)); } return 0; } /* http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1500 99 9 1 2 2 3 2 3 3 3 1 10 1 1 1 1 1 1 1 1 1 1 5 1 2 2 3 4 18 1 2 2 3 2 3 2 3 2 2 2 3 3 3 2 2 2 1 30 1 2 2 3 2 3 2 3 2 2 2 3 3 3 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 60 1 2 2 3 2 3 2 3 2 2 2 3 3 3 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 3 2 3 2 2 2 3 3 3 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 200 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 3 2 3 2 2 2 3 3 3 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 3 2 3 2 2 2 3 3 3 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 3 2 3 2 2 2 3 3 3 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 3 2 3 2 2 2 3 3 3 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 3 2 3 2 2 2 3 3 3 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 3 2 3 2 2 2 3 3 3 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 */
相关文章推荐
- UVA 10559 Blocks(区间DP&&递推)
- POJ 1390 Blocks(区间DP + 记忆化搜索)
- POJ 1390 Blocks (区间DP)
- ★Uva 1626 && POJ 1141 Brackets sequence 详细题解(区间DP+递归打印)
- POJ 1390 Blocks ||UVA 10559 - Blocks(记忆化搜索)
- poj 1390 Blocks 【区间dp】
- POJ 1141 / UVa 1626 Brackets Sequence (区间DP&打印路径)
- poj 1390 Blocks (区间dp)
- poj 1390 Blocks (经典区间dp 方块消除)
- [POJ1390]Blocks(区间dp)
- POJ 1390 Blocks (DP)
- 区间DP与贪心算法的联系(uav Cutting Sticks && poj Fence Repair(堆的手工实现))
- POJ 2528 & UVA 10587(线段树+离散+区间修改)
- UVa 348 Optimal Array Multiplication Sequence (区间DP&矩阵链乘,MCM)
- Blocks - POJ 1390 dp
- UVa 10559 Blocks(DP)
- UVA 10559 Blocks(记忆化dp)
- poj 1390 Blocks(dp)
- poj 1390 区间dp
- poj 1390 Blocks(DP)