Problem Statement

We have a board with a N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1×2 or 2×1 square.

Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors. Here, it is not always necessary to use all three colors.

Find the number of such ways to paint the dominoes, modulo 1000000007.

The arrangement of the dominoes is given to you as two strings S1 and S2 in the following manner:

  • Each domino is represented by a different English letter (lowercase or uppercase).
  • The j-th character in Si represents the domino that occupies the square at the i-th row from the top and j-th column from the left.

Constraints

  • 1≤N≤52
  • |S1|=|S2|=N
  • S1 and S2 consist of lowercase and uppercase English letters.
  • S1 and S2 represent a valid arrangement of dominoes.

Input

Input is given from Standard Input in the following format:

N
S1
S2

Output

Print the number of such ways to paint the dominoes, modulo 1000000007.


Sample Input 1

Copy
3
aab
ccb

Sample Output 1

Copy
6

There are six ways as shown below:


Sample Input 2

Copy
1
Z
Z

Sample Output 2

Copy
3

Note that it is not always necessary to use all the colors.


Sample Input 3

Copy
52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn

Sample Output 3

Copy
958681902

题解:
只有两行,简单题哈,就不多解释了.
定义F[i]为前i列的方案数
我们可以先压缩一下,s[i]=s[i+1]的缩成一个
可以开始讨论:
如果s1[i]==s2[i] & s1[i-1]==s2[i-1] F[i]=F[i-1]*2 i-1固定后,i有两种方案对应
s1[i]==s2[i] & s1[i-1]!= s2[i-1] F[i]=F[i-1] 表示i这个位置和i-1一一对应
s1[i]!= s2[i] & s1[i-1]==s2[i-1] F[i]=F[i-1]*2
s1[i]!= s2[i] & s1[i-1]!= s2[i-1] F[i]=F[i-1]*3 都不相同时有三种方案对应,可以手画下
 #include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int N=,mod=;
char s1[N],s2[N];long long f[N];
void work()
{
int l,n=;
scanf("%d",&l);
scanf("%s",s1+);
scanf("%s",s2+);
for(int i=;i<=l;i++){
if(s1[i]!=s1[i+]){
s1[++n]=s1[i];
s2[n]=s2[i];
}
}
if(s1[]==s2[])f[]=;
else f[]=;
for(int i=;i<=n;i++){
if(s1[i]==s2[i]){
if(s1[i-]!=s2[i-])f[i]+=f[i-];
else f[i]+=(f[i-]+f[i-])%mod;
}
else{
if(s1[i-]==s2[i-])f[i]+=(f[i-]+f[i-])%mod;
else f[i]+=(f[i-]*)%mod;
}
f[i]%=mod;
}
printf("%lld\n",f[n]);
} int main()
{
work();
return ;
}

 

AtCoder Beginner Contest 071 D - Coloring Dominoes的更多相关文章

  1. AtCoder Beginner Contest 071 ABCD

    1001 求个绝对值比较大小喽 1002 把字符串出现的字母记录一下,然后遍历a-z,谁第一个没出现就输出谁 1003 Problem Statement We have N sticks with ...

  2. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  3. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  4. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  5. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  6. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  7. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  8. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  9. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

随机推荐

  1. Linux安装mongodb总结

    由于自己的博客上线部署时需要用到mongodb来存储图片文件,所以先在本地电脑上安装了mongodb做测试,由于之前没接触过mongodb,所以安装过程中遇到了各种小问题,折腾了好久终于安装好并成功启 ...

  2. intellij idea 找不到或无法加载主类

    解决intellij idea 找不到或无法加载主类,请看以下图文介绍 然后idea会重启,等idea启动后 右侧的maven clean 一下,然后再compile就解决了

  3. EasyUI DataGrid 实现单行/多行编辑功能

    要实现 EasyUI DataGrid 的可编辑很简单,在需要编辑的列添加 editor [编辑器]就可以了. 单行编辑 // 初始化数据列表 function initDatagrid() { $( ...

  4. VMware虚拟机,从厚置备改成精简置备,并减小硬盘的实际占用空间

    工作中由于前期规划不足,导致磁盘空间分配较大,而且是厚置备.后期不再需要时,无法把用不到的空间释放出来,造成空间浪费.经过摸索和实验验证,总结出来一套方法. 风险提示:这个方法在我的环境中验证通过了, ...

  5. 新概念英语(1-141)Sally's first train ride

    Lesson 141 Sally's first train ride 萨莉第一交乘火车旅行 Listen to the tape then answer this question. Why was ...

  6. Bootstrap 栅格系统简单整理

    Bootstrap内置了一套响应式.移动设备优先的流式栅格系统,随着屏幕设备或视口(viewport)尺寸的增加,系统会自动分为最多12列. 总结一下我近期的学习Bootstrap的一些理解: 一.. ...

  7. PHP环境配置(1)

    Apache下载 Apache下载地址:http://httpd.apache.org/download.cgi 第一步:点击Files for Microsoft Windows 第二步:点击Apa ...

  8. Linux:sheel脚本for的用法,及日期参数+1day用法

    记录下shell的for的用法,及参数是日期的情况下,该日期+1day的用法: #!/usr/bin/env bash source /app/catt/login.sh p_days="2 ...

  9. eclipse 复制原项目工作空间

    eclipse 复制原项目工作空间 具体步骤: 1.首先把你需要升级的eclipse 下载并解压 2.解压好后,右击  3.进入后你能看到这样一个页面 4.我的安装路径D:\work\Eclipse\ ...

  10. requests之一:HTTP OAUTH认证(1)图形解释流程