codeforces 607B. Zuma 区间dp
给一个长度为n的序列, 每一次可以消去其中的一个回文串, 问最少几次才可以消完。
代码很清楚
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int dp[][], a[];
int dfs(int l, int r) {
if(dp[l][r])
return dp[l][r];
dp[l][r] = inf;
if(l == r)
return dp[l][r] = ;
if(r-l == )
return dp[l][r] = (a[l]==a[r])?:;
if(a[l] == a[r])
dp[l][r] = dfs(l+, r-);
for(int i = l; i<=r; i++) {
dp[l][r] = min(dp[l][r], dfs(l, i)+dfs(i+, r));
}
return dp[l][r];
}
int main()
{
int n;
cin>>n;
for(int i = ; i<=n; i++) {
scanf("%d", &a[i]);
}
cout<<dfs(, n);
return ;
}
codeforces 607B. Zuma 区间dp的更多相关文章
- CodeForces 607B zuma
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the ...
- CF607B Zuma(区间dp)
题意 题目链接 Sol 裸的区间dp,转移的时候判一下两个字符是否相等即可 #include<bits/stdc++.h> #define Pair pair<int, int> ...
- Palindromic characteristics CodeForces - 835D (区间DP,预处理回文串问题)
Palindromic characteristics of string s with length |s| is a sequence of |s|integers, where k-th num ...
- BZOJ 1032 JSOI 2007 祖码Zuma 区间DP
题目大意:依照祖玛的玩法(任意选颜色),给出一段区间.问最少用多少个球可以把全部颜色块都消除. 思路:把输入数据依照连续的块处理.保存成颜色和数量.然后用这个来DP.我们知道,一个单独的块须要两个同样 ...
- CodeForces - 1114D-Flood Fill (区间dp)
You are given a line of nn colored squares in a row, numbered from 11 to nn from left to right. The ...
- Codeforces 607B Zuma(区间DP)
题目大概说,有n个颜色的宝石,可以消除是回文串的连续颜色序列,问最少要几下才能全部消除. 自然想到dp[i][j]表示序列i...j全部消除的最少操作数 有几种消除的方式都能通过枚举k(i<=k ...
- Codeforces Round #336 (Div. 2) D. Zuma 区间dp
D. Zuma Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gems ...
- 【CF607B】Zuma——区间dp(记忆化搜索/递推)
以下是从中文翻译成人话的题面: 给定一个长度小于等于500的序列,每个数字代表一个颜色,每次可以消掉一个回文串,问最多消几次可以消完? (7.16) 这个题从洛谷pend回来以后显示有103个测试点( ...
- Codeforces 1107E(区间dp)
用solve(l, r, prefix)代表区间l开始r结束.带了prefix个前缀str[l](即l前面的串化简完压缩成prefix-1个str[l],加上str[l]共有prefix个)的最大值. ...
随机推荐
- python-操作exel(xlrd,xlwt)
1.使用第三方库 python中处理excel表格,常用的库有xlrd(读excel)表.xlwt(写excel)表.openpyxl(可读写excel表)等. xlrd读数据较大的excel表时效率 ...
- cf-A. Wet Shark and Odd and Even(水)
A. Wet Shark and Odd and Even time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- mac 版本号控制工具SmartSVN7.5.4(破解版)
SmartSVN7.5.4和破解工具,下载地址:http://download.csdn.net/detail/pearlhuzhu/7407319 操作步骤: 1.在MAC上选中smartsvn-m ...
- 我的小前端 (2)—— JQ和zepto
没有什么特别新技术,就是记录我做移动端遇到的问题 2016-02-16 关于JS库 JQ很简单,网上很多插件效果都依赖它,但JQ库很大 zepto.js用简单效果,很好用 <script src ...
- C++学习之文件的输入输出
C++学习之文件的输入输出 一.文件的打开与关闭 1.输出数据到文件 文件的操作需要包含fstream头文件,文件的操作对象为ifstream,ofstrea ...
- 【LeetCode题意分析&解答】34. Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
- 类比的方法学习Performance_schema
引用自:http://www.javacoder.cn/?p=332 MySQL在5.6版本中包含了一个强大的特性——performance-schema,合理的使用这个数据库中的表,能为我们解决一些 ...
- QT 下把编辑框内的中文字符转换为 char*
第一种方法 QString str(tr("你好")); wchar_t wc[100] = {0}; pEditShortDes->text().toWCharArray( ...
- .NET(C#):XmlReader和Whitespace以及MoveToContent和ReadToFollowing方法
原文 http://www.cnblogs.com/mgen/archive/2012/04/26/2471403.html XmlReader默认是读取XML文件中的Whitespace和注释的. ...
- chrome extensions
chrome web store AppsGamesExtensionsThemes CATEGORIES All FEATURESClear Runs Offline By ...