前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >BZOJ1802: [Ahoi2009]checker(性质分析 dp)

BZOJ1802: [Ahoi2009]checker(性质分析 dp)

作者头像
attack
发布2019-02-26 12:09:32
3270
发布2019-02-26 12:09:32
举报

题意

题目链接

Sol

一个不太容易发现但是又很显然的性质:

如果有两个相邻的红格子,那么第一问答案为0, 第二问可以推

否则第一问答案为偶数格子上的白格子数,第二问答案为偶数格子上的红格子数

代码语言:javascript
复制
#include<bits/stdc++.h> 
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long 
#define LL long long 
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int MAXN = 1001, mod = 1e9 + 7, INF = 1e9 + 10;
const double eps = 1e-9;
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline LL add(A x, B y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
template <typename A, typename B> inline void add2(A &x, B y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
template <typename A, typename B> inline LL mul(A x, B y) {return 1ll * x * y % mod;}
template <typename A, typename B> inline void mul2(A &x, B y) {x = (1ll * x * y % mod + mod) % mod;}
template <typename A> inline void debug(A a){cout << a << '\n';}
template <typename A> inline LL sqr(A x){return 1ll * x * x;}
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, a[MAXN];
LL f[MAXN];
signed main() {
    N = read();
    int ans[2] = {0, 0}, flag = 0;
    memset(f, 0x3f, sizeof(f));
    for(int i = 1; i <= N; i++) {
        a[i] = read();
        if(i > 2 && a[i] && a[i] == a[i - 1]) flag = 1;
        if((!(i & 1))) ans[a[i]]++;
        if(a[i]) f[i] = 1;
    }
    if(!flag) {printf("%d\n%d", ans[0], ans[1]); return 0;}
    for(int i = 2; i < N; i++) {
        if(a[i] && a[i + 1]) {
            for(int j = i - 1; j > 1; j--) chmin(f[j], f[j + 1] + f[j + 2]);
            for(int j = i + 2; j < N; j++) chmin(f[j], f[j - 1] + f[j - 2]);
        }
    }
    LL out = 0;
    for(int i = 2; i < N; i += 2) out += f[i];
    cout << 0 << "\n" << out;
    return 0;
}
/*
5

0 0 1 1 0
*/
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-01-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题意
  • Sol
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档