您的位置:首页 > Web前端 > JavaScript

bzoj1032 [JSOI2007]祖码Zuma

2015-09-14 19:24 621 查看

1032: [JSOI2007]祖码Zuma

Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 672 Solved: 335
[Submit][Status][Discuss]

Description

这是一个流行在Jsoi的游戏,名称为祖玛。精致细腻的背景,外加神秘的印加音乐衬托,彷佛置身在古老的国度里面,进行一个神秘的游戏——这就是著名的祖玛游戏。祖玛游戏的主角是一只石青蛙,石青蛙会吐出各种颜色的珠子,珠子造型美丽,并且有着神秘的色彩,环绕着石青蛙的是载着珠子的轨道,各种颜色的珠子会沿着轨道往前滑动,石青蛙必需遏止珠子们滚进去轨道终点的洞里头,如何减少珠子呢?就得要靠石青蛙吐出的珠子与轨道上的珠子相结合,颜色相同者即可以消失得分!直到轨道上的珠子通通都被清干净为止。 或许你并不了解祖玛游戏。没关系。这里我们介绍一个简单版本的祖玛游戏规则。一条通道中有一些玻璃珠,每个珠子有各自的颜色,如图1所示。玩家可以做的是选择一种颜色的珠子(注意:颜色可以任选,这与真实游戏是不同的)射入某个位置。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name) {
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
}

const int N = 510;
int m, Arr
, n, Color
, Num
;
int Dp

;
bool Visit

;

inline void Input() {
scanf("%d", &m);
For(i, 1, m) scanf("%d", Arr+i);
}

inline int Search(int L, int R) {
if(Visit[L][R]) return Dp[L][R];
Visit[L][R] = 1;
if(L == R) return Dp[L][R] = max(3-Num[L], 1);
if(L > R) return Dp[L][R] = INF;

int Ret = INF, tmp;
For(i, L, R-1) {
tmp = Search(L, i)+Search(i+1, R);
Ret = min(Ret, tmp);
}
if(Color[L] == Color[R]) {
tmp = max(3-Num[L]-Num[R], 0)+Search(L+1, R-1);
Ret = min(Ret, tmp);
}
return Dp[L][R] = Ret;
}

inline void Solve() {
Arr[0] = -1;
For(i, 1, m) {
if(Arr[i] != Arr[i-1]) Color[++n] = Arr[i];
Num
++;
}

int Ans = Search(1, n);
printf("%d\n", Ans);
}

int main() {
#ifndef ONLINE_JUDGE
SetIO("1032");
#endif
Input();
Solve();
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: