记录编号 |
22175 |
评测结果 |
AAAWWWWWWA |
题目名称 |
拯救 |
最终得分 |
40 |
用户昵称 |
wangwangdog |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
0.005 s |
提交时间 |
2010-11-17 15:39:00 |
内存使用 |
0.28 MiB |
显示代码纯文本
#include<stdio.h>
long long i,n,a[1001],da[1001],db[1001],dc[1001];
char cc;
int main()
{
FILE *fin,*fout;
fin=fopen("savey.in","rb");
fout=fopen("savey.out","wb");
fscanf(fin,"%lld\n",&n);
for(i=1;i<=n;i++)
{
fscanf(fin,"%lld",&a[i]);
}
if(n==1)
{
if(a[1]==0)fprintf(fout,"0");
if(a[1]==1)fprintf(fout,"1");
}
if(n==2)
{
if(a[1]==1&&a[2]==1)fprintf(fout,"2");
if(a[1]==1&&a[2]==0)fprintf(fout,"1");
if(a[1]==0&&a[2]==1)fprintf(fout,"3");
if(a[1]==0&&a[2]==0)fprintf(fout,"0");
}
if(n!=1&&n!=2)
{
da[1]=a[1];
if(a[1]==1)db[1]=0;
else db[1]=1;
dc[1]=1;
for(i=2;i<=n;i++)
{
if(a[i]==0)
{
da[i]=da[i-1];
db[i]=db[i-1]+1+dc[i-1];
dc[i]=dc[i-1]+1+dc[i-1];
}
if(a[i]==1)
{
db[i]=da[i-1];
da[i]=db[i-1]+1+dc[i-1];
dc[i]=dc[i-1]+dc[i-1]+1;
}
}
fprintf(fout,"%lld",da[n]);
}
fclose(fin);
fclose(fout);
return 0;
}