ACM 训练日志记录 · 思考 · 成长 提交 / 修改记录
郭一鸣 / 题目列表训练档案
导出

2256B Codeforces Round 1116 (Div. 2)

来源:Codeforces ★ 1000

本题活力0.24按难度、完成结果与训练证据估算

算法如山行则将至

题目描述

将字符串中的?替换为0或1,使相邻多米诺重量不同,求方案数。

代码

#include<iostream>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
        int n;string s;
        cin>>n>>s;
        int ans=0;
        for(int fir=0;fir<=1;fir++)
        {
            for(int sec=0;sec<=1;sec++)
            {
                bool flag=true;
                for(int i=0;i<n;i++)
                {
                    int a;
                    if(i%4==0)a=fir;
                    else if(i%4==1)a=sec;
                    else if(i%4==2)a=1-fir;
                    else a=1-sec;
                    if(s[i]!='?'&&s[i]-'0'!=a)
                    {
                        flag=false;break;
                    }
                }
                if(flag==true)ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}