UVA 10559 Blocks(记忆化dp)
来源:互联网 发布:弹丸论破未来篇 知乎 编辑:程序博客网 时间:2024/06/07 03:23
这题在poj上做过,之前的博客已经有详细解释了。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>using namespace std;#define rep(i,a,b) for(int i=(a);i<=(b);i++)#define ss(x) scanf("%d",&x)const int maxn=200+10;struct blocks{ int amount,color;};int n;int a[maxn];vector<blocks> v;int f[maxn][maxn][maxn];int dp(int l,int r,int ex_len){ if(f[l][r][ex_len]>=0) return f[l][r][ex_len]; int ans=(v[r].amount+ex_len)*(v[r].amount+ex_len); if(l==r) return ans; ans+=dp(l,r-1,0); rep(i,l,r-1){ if(v[i].color!=v[r].color) continue; ans=max(ans,dp(l,i,v[r].amount+ex_len)+dp(i+1,r-1,0)); } return f[l][r][ex_len]=ans;}int main(){ int kase=0; int t; ss(t); while(t--) { v.clear(); ss(n); rep(i,1,n) ss(a[i]); rep(i,1,n) {if(a[i]!=a[i-1]) {v.push_back((blocks){1,a[i]});}else v[v.size()-1].amount++;} memset(f,-1,sizeof(f)); printf("Case %d: %d\n",++kase,dp(0,(int)v.size()-1,0)); } return 0;}
0 0
- UVA 10559 Blocks(记忆化dp)
- UVA - 10559 Blocks 记忆化搜索
- POJ 1390 Blocks ||UVA 10559 - Blocks(记忆化搜索)
- UVA - 10559 Blocks(DP)
- UVa 10559 Blocks(DP)
- 【DP+记忆化搜索】PKU-1390-Blocks
- Uva 10559 & POJ 1390 Blocks 区间dp
- UVA 607 (dp记忆化搜索)
- UVA 12063(dp记忆化)
- UVA 10559 Blocks
- poj 1609 Tiling Up Blocks dp入门之记忆化搜索
- Uva 10891 Game of Sum - 区间DP..记忆化搜索
- uva 10453 - Make Palindrome (区间dp,记忆化搜索)
- UVA 10891 Game of Sum dp(记忆化搜索)
- 28.uva 10891 Game of Sum 记忆化dp
- uva 10599 - Robots(II) (dp | 记忆化搜索)
- UVA 10626Buying Coke(dp + 记忆化搜索)
- UVA 10817 - Headmaster's Headache(dp记忆化搜索)
- VS2015给命令行添加参数
- 机器学习之(四)特征工程以及特征选择的工程方法
- multirotor flight control
- Bellman及其优化
- BZOJ4382[POI2015] Podział naszyjnika
- UVA 10559 Blocks(记忆化dp)
- bzoj 4515: [Sdoi2016]游戏(树链剖分+线段树)
- CountDownLatch的介绍和使用
- Dijkstar及其优先队列优化
- HTML5中的save()和restore()方法的用法
- 机器学习之(三)梯度下降法的三种形式BGD、SGD以及MBGD
- CSRF跨域请求伪造
- 理解RESTful架构
- dinic网络最大流