Blocks UVA
来源:互联网 发布:sportsdt体育大数据 编辑:程序博客网 时间:2024/06/06 05:53
解题思路本身不复杂,但是难想到,考虑的点主要在于对于一部分已知的颜色,有两种选择:第一种是将这一部分的颜色直接全部消除,立即得到相应的分数之后再接着进行后续的分析操作;第二种是尽量将这种颜色的部分进行拼接(大意是这样,可能不太准确),然后进行消除,对于这两种选择,选择最大的结果作为最终的结果,紫书中作者给出了一种很巧妙的记录方式,记录的是相应的下标以及右下标的右侧颜色相同的块的个数来解决这个问题的,具体实现见如下代码:
#include<iostream>#include<vector>#include<string>#include<set>#include<stack>#include<queue>#include<map>#include<algorithm>#include<cmath>#include<iomanip>#include<cstring>#include<sstream>#include<cstdio>#include<deque>using namespace std;int t;int color[210];int result[210][210][210];int dp(int i, int j,int k){if (i > j) return 0;int& res = result[i][j][k];if (res >= 0) return res;int p = j;while (i <= p&&color[p] == color[j]) p--;p++;res = dp(i, p - 1, 0) + (j - p + 1 + k)*(j - p + 1 + k);for (int q = i; q < p; q++){if (color[q] == color[j] && color[q] != color[q + 1])res = max(res, dp(q + 1, p - 1, 0) + dp(i, q, j - p + 1 + k));}return res;}int main(){cin >> t;int Case = 0;while (t--){int n;cin >> n;for (int i = 0; i < n; i++) cin >> color[i];memset(result,-1,sizeof(result));cout << "Case " << ++Case << ": " << dp(0, n - 1, 0) << endl;}return 0;}
阅读全文
0 0
- Blocks UVA
- UVA 10559 Blocks
- UVA The Blocks Problem
- UVA - 10559 Blocks(DP)
- UVa 10365 - Blocks
- uva 101 the blocks problem
- uva 101 the blocks problem
- UVa 101 The Blocks Problem
- uva 101 - The Blocks Problem
- uva 101 - The Blocks Problem
- UVa 101 - The Blocks Problem
- uva 101 - The Blocks Problem
- UVa 101 - The Blocks Problem
- Uva-101-The Blocks Problem
- Uva 101 - The Blocks Problem
- uva 101 The Blocks Problem
- UVa 101 - The Blocks Problem
- uva 101 - The Blocks Problem
- Mybatis(问题一)开发过程中常见的问题
- Android视图绘制流程完全解析,带你一步步深入了解View(二)
- 三、Audio 系统声音
- phpstorm使用教程
- 【IO】out.println 和err.println的执行顺序
- Blocks UVA
- 自己总结的在编程中的一些小技巧
- Scrapy之路第一篇
- Android视图状态及重绘流程分析,带你一步步深入了解View(三)
- Sql 四大排名函数(ROW_NUMBER、RANK、DENSE_RANK、NTILE)简介
- JavaSE集合框架-01-集合框架体系及表数据结构
- effective c++读书笔记(三)
- AUTOCAD学习笔记3:常用电器元件的绘制
- Quora比赛代码学习笔记