2024 ICPC 江西省赛 K. Magic Tree

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≤10^{5}) 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列时方案数翻倍。观察可得总方案数为2^{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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值