AtCoder Regular Contest 081 D
来源:互联网 发布:淘宝日本代购退换 编辑:程序博客网 时间:2024/06/06 14:15
D - Coloring Dominoes
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
We have a board with a 2×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
题目链接
题解:就第一块是有三种情况
abb
acc 如果这种情况就乘2
bbcc
ddee如果这种情况乘3
#include <iostream>#include <stdio.h>#include <algorithm>#include <vector>#include <string.h>#include <map>#define int long longusing namespace std;const int mod=1000000007;char str[12][100];signed main(){ int n; scanf("%lld",&n); for(int i=0;i<2;i++){ scanf("%s",str[i]); } bool flag=false; int f=0; int t=1; for(int i=0;i<n;i++){ if(str[0][i]==str[0][i+1]){ if(f==0){ t*=3; t*=2; f=1; } else { if(flag){ t*=2; t*=1; } else { t*=3; } } flag=false; i++; } else { if(str[0][i]==str[1][i]){ if(f==0){ t*=3; f=1; } else { if(flag) t*=2; else t*=1; } flag=true; } } t%=mod; } cout<<t<<endl; return 0;}
- AtCoder Regular Contest 081 D
- AtCoder Regular Contest 069 D
- AtCoder Regular Contest 073 D
- AtCoder Regular Contest 077-D
- AtCoder Regular Contest 078 D
- AtCoder Regular Contest 078 D
- AtCoder Regular Contest 078-D
- AtCoder Regular Contest 079-D
- AtCoder Regular Contest 079 D
- AtCoder Regular Contest 080-D
- AtCoder Regular Contest 068-D
- atcoder AtCoder Regular Contest 084 D
- AtCoder regular contest 081 E
- Atcoder Regular Contest 081 总结
- AtCoder Regular Contest 076 D Built?(kruskal)
- 【Atcoder】Regular Contest 079 D E
- AtCoder Regular Contest 079 C D E
- AtCoder Regular Contest 080 C , D
- leetcode 223. Rectangle Area
- 在MvvmLight中View和ViewModel的绑定
- 文件的上传(表单上传和ajax文件异步上传)
- Entity Framework Core 2.0 全局查询过滤器
- 全文检索引擎Solr系列—–全文检索基本原理
- AtCoder Regular Contest 081 D
- apt-get安装源替换 阿里云源
- C++换钱的最少货币数 动态规划
- JS的类型转换,强制转换和隐式转换
- struts2学习笔记(二)---实例应用
- HDU6153-A Secret
- 新朋实验室之玩具遥控车改装为ARDUINO蓝牙遥控小车(代码及制作过程开源)
- Monitorix-免费开源的单机Linux监控工具
- 装饰器模式(Decorator)和代理模式(Proxy)