K. Magic Tree
time limit per test: 1 second
memory limit per test: 1024 megabytes
Starlight Glimmer has a 2-row, m-column grid, with row i and column j labeled as (i,j).
She performs a depth-first search starting from the lattice labeled as (1,1) (i.e., the first row and first column), and each lattice can reach a lattice that is adjacent to at least one of its edges. Since the search process does not repeatedly visit lattices, a tree can be used to describe the search process.
Now she wants to know how many possible results of the labelled trees there are in total, and to avoid the answer being too large, you need to modulo 998244353 to print it.
Formally, we use a stack S to describe the depth-first search process and a edge set E to indicate a labelled tree.
In depth-first search process, fristly push lattice (1,1) in stack S then goto the process as follows:
If S is empty, end the process.Suppose the top element of the stack is (x,y) whose unvisit legal adjacent lattice is set N.
If N is empty, pop (x,y) and goto step 1.
Randomly choose an element (z,w) in N, push it in the stack S and insert edge (x,y)→(z,w) in edge set E, mark lattice (z,w) as having been visited.
Goto step 1.
For lattice (x,y), if a lattice (z,w) satisfies |z−x|+|w−y|=1,z∈{1,2},w∈{1,2,3,…,m} and havn't been visited, it is a unvisit legal adjacent lattice which will be in set N.
The process may produce many different kinds of edge set E, the number of it is the labelled trees describe above.
Input
The first line contains an integer m (1≤m≤) indicating the column of the grid.
Output
Print a single integer, represents the number of trees modulo 998244353.
Example
input
3
output
4
Note
Next page is a specific illustration of the 4 labeled trees when m equals 3.
【思路分析】
诈骗题。可从1到m做线性规划,显然每次增加1列时方案数翻倍。观察可得总方案数为。
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <cstring>
#include <iomanip>
#include <set>
#define i64 long long
using namespace std;
i64 mod = 998244353;
void solve() {
i64 m, res = 1;
cin >> m;
while (--m) {
res *= 2;
res %= mod;
}
cout << res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}