C. Tiles
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black part as depicted in the figure below.
The dimension of this tile is perfect for this kitchen, as he will need exactly w×h tiles without any scraps. That is, the width of the kitchen is w tiles, and the height is h tiles. As each tile can be rotated in one of four ways, he still needs to decide on how exactly he will tile the floor. There is a single aesthetic criterion that he wants to fulfil: two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black.
The picture on the left shows one valid tiling of a 3×2 kitchen. The picture on the right shows an invalid arrangement, as the bottom two tiles touch with their white parts.
Find the number of possible tilings. As this number may be large, output its remainder when divided by 998244353 (a prime number).
Input
The only line contains two space separated integers w, h (1≤w,h≤1000) — the width and height of the kitchen, measured in tiles.
Output
Output a single integer n — the remainder of the number of tilings when divided by 998244353.
Examples
input
2 2
output
16
input
2 4
output
64
**题意:**给出n*m的方格,每相邻两个格子的黑色边框不能相邻,问有多少种组合方式。
**思路:**由数据可分析出答案为2^(n+m)次方,直接快速幂。
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
ll ksm(ll a, ll n) {
ll res = 1;
while (n) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main() {
int n, m;
ll num;
scanf("%d%d", &n, &m);
num = (ll)(n + m);
ll ans = ksm(2, num);
printf("%lld\n", ans);
return 0;
}