题目描述

若有两个红格相邻
  第一问的答案为0,所有位置上的棋子都可以通过在这两个格子上放棋子得到
  第二设f[i]表示想让第i个格子上有棋子需要放的棋子数
若没有,第一问答案为偶数格子上白格的个数,第二问为偶数格子上红格的个数

#include<complex>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1e3+;
int n;
bool flag;
long long f[N];
bool a[N];
int qread()
{
int x=;
char ch=getchar();
while(ch<'' || ch>'')ch=getchar();
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
a[i]=qread();
for(int i=;i<=n;i++)
if(a[i]&a[i-])flag=;
if(!flag)
{
int b=,c=;
for(int i=;i<=n;i+=)
a[i]?c++:b++;
printf("%d\n%d\n",b,c);
return ;
}
memset(f,0x3f,sizeof(f));
f[]=;
for(int i=;i<=n;i++)
if(a[i])f[i]=;
for(int i=;i<=n;i++)
if(a[i]&a[i+])
{
for(int j=i-;j>;j--)
f[j]=min(f[j],f[j+]+f[j+]);
for(int j=i+;j<=n;j++)
f[j]=min(f[j],f[j-]+f[j-]);
}
long long ans=;
for(int i=;i<=n;i+=)
ans+=f[i];
printf("0\n%lld\n",ans);
return ;
}

BZOJ 1802: [Ahoi2009]checker的更多相关文章

  1. 【BZOJ1802】[AHOI2009]checker(动态规划)

    [BZOJ1802][AHOI2009]checker(动态规划) 题面 BZOJ 洛谷 题解 首先自己观察一波,发现如果有相邻两个格子都是红色的话,那么显然可以在任意位置都存在一个跳棋.可以让两个位 ...

  2. Bzoj 1081 [Ahoi2009] chess 中国象棋

    bzoj 1081 [Ahoi2009] chess 中国象棋 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1801 状态比较难设,的确 ...

  3. bzoj 1799: [Ahoi2009]self 类似的分布 解读

    [原标题] 1799: [Ahoi2009]self 同类分布 Time Limit: 50 Sec  Memory Limit: 64 MB Submit: 554  Solved: 194 [id ...

  4. BZOJ 1797: [Ahoi2009]Mincut 最小割

    1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2076  Solved: 885[Submit] ...

  5. bzoj 1800: [Ahoi2009]fly 飞行棋 暴力

    1800: [Ahoi2009]fly 飞行棋 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline ...

  6. [BZOJ 1801] [Ahoi2009]chess 中国象棋 【DP】

    题目链接:BZOJ - 1801 题目分析 对于50%的数据是可以直接状压 DP 的. 对于100%的数据,使用递推的 DP .(或者这只叫递推不叫 DP ?) 可以发现,每一行和每一列的棋子个数不能 ...

  7. BZOJ 1801: [Ahoi2009]chess 中国象棋( dp )

    dp(i, j, k)表示考虑了前i行, 放了0个炮的有j列, 放了1个炮的有k列. 时间复杂度O(NM^2) -------------------------------------------- ...

  8. BZOJ 1800: [Ahoi2009]fly 飞行棋( 枚举 )

    O(N2)算出有x条直径然后答案就是x(x-1)/2...这个数据范围是闹哪样! ----------------------------------------------------------- ...

  9. BZOJ 1797: [Ahoi2009]Mincut 最小割( 网络流 )

    先跑网络流, 然后在残余网络tarjan缩点. 考虑一条边(u,v): 当且仅当scc[u] != scc[v], (u,v)可能出现在最小割中...然而我并不会证明 当且仅当scc[u] = scc ...

随机推荐

  1. 如何在ASP.NET Core Web API中使用Mini Profiler

    原文如何在ASP.NET Core Web API中使用Mini Profiler 由Anuraj发表于2019年11月25日星期一阅读时间:1分钟 ASPNETCoreMiniProfiler 这篇 ...

  2. C#读写设置修改调整UVC摄像头画面-倾斜

    有时,我们需要在C#代码中对摄像头的倾斜进行读和写,并立即生效.如何实现呢? 建立基于SharpCamera的项目 首先,请根据之前的一篇博文 点击这里 中的说明,建立基于SharpCamera的摄像 ...

  3. delegate、Action、Func的用法

    委托的特点 委托类似于 C++ 函数指针,但它们是类型安全的. 委托允许将方法作为参数进行传递. 委托可用于定义回调方法. 委托可以链接在一起. delegate的用法 delegate void B ...

  4. only size-1 arrays can be converted to Python scalars

    python版本:3.6.5 opencv版本:3.2.0 使用的jupyter notebook 源码如下: import cv2 import numpy as np import matplot ...

  5. <url-pattern>写成/和/*的区别- CSDN博客

    <url-pattern>/</url-pattern>: 会匹配到/springmvc这样的路径型url,不会匹配到模式为*.jsp这样的后缀型url. <url-pa ...

  6. Nginx反向代理其他使用方式

    Nginx反向代理在生产环境中使用很多的. 场景1: 域名没有备案,可以把域名解析到香港一台云主机上,在香港云主机做个代理,而网站数据是在大陆的服务器上. 示例1: server { listen 8 ...

  7. ObjC: 源文件的组织

    转自:http://marshal.easymorse.com/tech/objc-%e6%ba%90%e6%96%87%e4%bb%b6%e7%9a%84%e7%bb%84%e7%bb%87 最简单 ...

  8. AttributeError: module 'matplotlib' has no attribute 'verbose'

    AttributeError: module 'matplotlib' has no attribute 'verbose' 翻译:attributeError:模块“matplotlib”没有“ve ...

  9. Unity手游汉化笔记②:使用UABE替换TTF字体

    总的笔记:https://www.cnblogs.com/guobaoxu/p/12055930.html 目录 一.分析 二.思路 三.具体实践 四.总结 Unity版本:2018.4.5f1 工具 ...

  10. TensorFlow NMT的词嵌入(Word Embeddings)

    本文转载自:http://blog.stupidme.me/2018/08/05/tensorflow-nmt-word-embeddings/,本站转载出于传递更多信息之目的,版权归原作者或者来源机 ...