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. python解释NTFS runlist的代码(文章转自北亚数据恢复张宇工程师)

    代码如下: 执行效果如下:root@zhangyu-VirtualBox:~/NTFS-5# python3 read_runlist.py mft_source.img ***参数数量或格式错误! ...

  2. WPF treeview扩展

    记录一下工作中遇到的问题,以便以后忘记了可以来看. 在工作中遇到一个问题,就是要实现类型如下的界面,没有使用Telerik和Dev库.本来最开始是想使用Datagrid,但不知道怎么实现treevie ...

  3. Mego开发文档 - 快速开始

    Mego 快速开始 我们将创建一个简单的数据新增及查询来演示 Mego 的使用过程.演示中都是使用 Visual Studio 2017 作为开发工具,SQL Server 2012 作为数据库. 创 ...

  4. api-gateway实践(09)支持rest服务注册

    一.GET-GET 1.前端定义 2.后端定义 2.1.基础定义 2.2.path参数.head参数.query参数 2.3.常量参数 2.4.系统参数 2.5.结果定义 二.POST-POST 1. ...

  5. OAuth2.0学习(1-13)oauth2.0 的概念:资源、权限(角色)和scope

    mkk 关于资源的解释 : https://andaily.com/blog/?cat=19 resource用于将系统提供的各类资源进行分组管理, 每一个resource对应一个resource-i ...

  6. Python系列-python函数

    函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.你已经知道Python提供了许多内建函数,比如print().但你也可以自己创建函数,这 ...

  7. Android 6.0 以后webview不加载图片的问题

    /** * Webview在安卓5.0之前默认允许其加载混合网络协议内容 * 在安卓5.0之后,默认不允许加载http与https混合内容,需要设置webview允许其加载混合网络协议内容 */if ...

  8. 其实你并不懂如何定义一个 PHP 函数

    <?php function divide($dividend, $divisor){ return $dividend / $divisor; } echo divide(12, 4); ec ...

  9. SpringMVC(三):@RequestMapping中的URL中设定通配符,可以使用@PathVariable映射URL绑定的占位符

    1)带占位符的URL是Spring3.0新增的功能,该功能在SpringMVC向REST目标挺进发展过程中具有里程碑的意义. 2)通过@PathVariable可以将URL中占位符参数绑定到控制器处理 ...

  10. Hadoop API:遍历文件分区目录,并根据目录下的数据进行并行提交spark任务

    hadoop api提供了一些遍历文件的api,通过该api可以实现遍历文件目录: import java.io.FileNotFoundException; import java.io.IOExc ...