[POI2013]BAJ-Bytecomputer
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[POI2013]BAJ-Bytecomputer相关的知识,希望对你有一定的参考价值。
?????????ems math print string cpp else bool main space
?????????
???????????????????????????????????????1???????????????-1
??????dp??????(f[i][j])????????????(i)??????????????????????????????(j-2)???????????????????????????
???????????????????????????????????????????????????????????????
??????????????????????????????min??????
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
void read(int &x) {
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=1e6+1;
int n,a[maxn],f[maxn][4],ans;
int main()
{
read(n);
for(rg int i=1;i<=n;i++)read(a[i]),a[i]+=2;
memset(f,63,sizeof f);f[1][a[1]]=0;
for(rg int i=2;i<=n;i++)
{
if(a[i]==1)
{
f[i][1]=min(f[i-1][1],f[i][1]);
f[i][3]=min(f[i-1][3]+2,f[i][3]);
}
if(a[i]==2)
{
f[i][1]=min(f[i-1][1]+1,f[i][1]);
f[i][2]=min(f[i-1][2],min(f[i-1][1],f[i][2]));
f[i][3]=min(f[i-1][3]+1,f[i][3]);
}
if(a[i]==3)
{
f[i][1]=min(f[i-1][1]+2,f[i][1]);
f[i][2]=min(f[i-1][1]+1,f[i][2]);
f[i][3]=min(f[i-1][1],min(f[i-1][2],min(f[i-1][3],f[i][3])));
}
}
ans=min(f[n][1],min(f[n][2],f[n][3]));
if(ans<=1e9)printf("%d
",ans);
else printf("BRAK
");
}
以上是关于[POI2013]BAJ-Bytecomputer的主要内容,如果未能解决你的问题,请参考以下文章
P3558 [POI2013]BAJ-Bytecomputer(线性dp)