【BZOJ1970】[AHOI2005]矿藏编码(模拟)
【BZOJ1970】[AHOI2005]矿藏编码(模拟)
题面
题解
随便写个高精度模拟一下就完了。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
int n,l,k;char ch[500];
struct BigInt
{
int s[2000],ws;
void init(){memset(s,0,sizeof(s));s[ws=1]=0;}
void output(){for(int i=ws;i;--i)printf("%d",s[i]);puts("");}
void eql(ll x){init();ws=0;while(x)s[++ws]=x%10,x/=10;}
}ans,P;
BigInt operator+(BigInt a,BigInt b)
{
int ws=max(a.ws,b.ws);
for(int i=1;i<=ws;++i)a.s[i]+=b.s[i];
for(int i=1;i<=ws;++i)a.s[i+1]+=a.s[i]/10,a.s[i]%=10;
while(a.s[ws+1])++ws,a.s[ws+1]+=a.s[ws]/10,a.s[ws]%=10;
a.ws=ws;return a;
}
BigInt operator*(BigInt a,BigInt b)
{
BigInt ret;int ws=a.ws+b.ws;ret.init();
for(int i=1;i<=a.ws;++i)
for(int j=1;j<=b.ws;++j)
ret.s[i+j-1]+=a.s[i]*b.s[j];
for(int i=1;i<=ws;++i)ret.s[i+1]+=ret.s[i]/10,ret.s[i]%=10;
while(!ret.s[ws])--ws;
ret.ws=ws;return ret;
}
void dfs(int K)
{
++l;
if(ch[l]=='0')P.eql(1ll<<K),ans=ans+P*P;
else if(ch[l]=='1');
else dfs(K-1),dfs(K-1),dfs(K-1),dfs(K-1);
}
int main()
{
scanf("%d",&k);scanf("%s",ch+1);
n=strlen(ch+1);dfs(k);
ans.output();
return 0;
}