bzoj1032 [JSOI2007]祖码Zuma
2015-09-14 19:24
621 查看
1032: [JSOI2007]祖码Zuma
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 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
相关文章推荐
- JS中复制数组
- JSP 四个内置对象的保存范围
- JSP 响应对象 response
- js校验15位/18位身份证件号(地区、生日、性别)
- JSP 对话对象 Session
- JSP中JSP中include指令和include行为的区别
- Js_动画显示背景图片
- Javascript常用前台表单验证
- grunt.js配置
- encodeURIComponent()对js参数进行编码,防止错误值
- javascript 获取时间 转换为 Y-m-d H:i:s
- js自己封装方法
- json遍历
- 实现图片轮流滑动
- js跨域问题的解决
- <JSP>page与pageContext什么关系
- js 删除 textarea换行符
- 一般处理程序返回json
- 限制文本框输入指定字符
- MVC Action返回Json