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. 解决IE8下CSS3选择器 :nth-child() 不兼容的问题

    1.定义和用法 :nth-child(n) 选择器匹配属于其父元素的第 N 个子元素,不论元素的类型. n 可以是数字.关键词或公式. <ul> <li>1</li> ...

  2. 新概念英语(1-57)An unusual day

    新概念英语(1-57)An unusually day What is Mr. Sawyer doing tonight? It is eight o'clock. The children go t ...

  3. io使用的设计模式

    File f = new File("c:/a.txt"); 1. FileInputStream fis = new FileInputStream(f); 2. Reader ...

  4. CentOS ping www.baidu.com 报错 name or service not know

    今天尝试安装了centos系统 玩一玩 刚刚装好的操作系统 ping www.baidu.com的时候  报出 name or service not known 查了好多资料,都没有很好的解决 最后 ...

  5. Java基础语法<六> 数组 Arrays

    笔记整理 来源于<Java核心技术卷 I > <Java编程思想>   允许数组长度为0 new element[0] 数组长度为0与null不同   1. 数组拷贝 允许将一 ...

  6. 有没有想过css定位与xpath的区别

    我是这样理解的, css选择如同你尽可能具体的描述一个元素的形态, 包括他的: 标签, 类, id 以及这些的组合, 目标是尽可能确定元素的唯一坐标 , 以方便选择. 而xpath是根据元素的路径去确 ...

  7. Java集合框架的四个接口

    接口 [四个接口  collection  list  set  map 的区别] collection 存储不唯一的无序的数据 list 存储有序的不唯一的数据 set   存储无序的唯一的数据 m ...

  8. 创建第一个Django项目

    第一个Django项目 命令行下使用如下命令创建一个名为"mysite"的Django项目: django-admin startproject mysite 这将会在当前位置创建 ...

  9. glut 深度测试无不起作用问题解决

    OpenGL中使用glEnable(GL_DEPTH_TEST)后深度测试没有起作用,发现深度缓冲没有创建.glut库在兼容模式(GL_COMPATIBILITY_PROFILE)下displaymo ...

  10. 查看 Secret - 每天5分钟玩转 Docker 容器技术(156)

    可以通过 kubectl get secret 查看存在的 secret. 显示有两个数据条目,kubectl describe secret 查看条目的 Key: 如果还想查看 Value,可以用  ...