venile Galant(简单dp+逆元)

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld

题目描述

As a self-proclaimed practitioner of the Guhua Clan ( Aka. Kokaha)'s arts, Xingqiu ( Aka. Yukuaki) is planning to forge a longsword with length n. The following picture shows a longsword with length n = 4.


A longsword with length n = 4 (not really long though).

In order to forge his longsword, Xingqiu has gotten some materials. There are two types of materials, and Xingqiu has infinite pieces of both of them. The following picture shows the shapes of materials.


The shapes of materials.

Now, Xingqiu wants to calculate the number of ways to forge his longsword. As the result can be very large, you should output the answer modulo 998244353.

输入描述:

The first line contains a single integer n (2≤n≤1062 \leq n \leq 10^62n106) --- the length of Xingqiu's longsword.

输出描述:

Output a single integer --- the number of ways to forge Xingqiu's longsword modulo 998244353.
示例1

输入

复制 2
2

输出

复制 1
1
示例2

输入

复制 4
4

输出

复制 1
1
示例3

输入

复制 5
5

输出

复制 2
2
示例4

输入

复制 7
7

输出

复制 4
4
示例5

输入

复制 12
12

输出

复制 25
25
示例6

输入

复制 114514
114514

输出

复制 548004034
548004034

备注:

In the first example (n = 4), there are 1 way as following:



In the second example (n = 5), there are 2 ways as following:



In the third example (n = 7), there are 4 ways as following:



As is shown, materials can be rotated and flipped, but can't be cut.
uvenile Galant
返回全部题目

列表加载中...
#include<iostream>
using namespace std;
#define ll long long
const int maxn=1e6+5;
const ll Mod=998244353;
ll dp[maxn][6];
ll fixll(ll n)
{
    return n%Mod;
}
ll quick_mod(ll x)
{
    ll md=Mod-2;
    ll op=1;
    while(md)
    {
        if(md&1)
            op=(op*x)%Mod;
        x=(x*x)%Mod;
        md>>=1;
    }
    return op;
}
int main()
{
    int n;
    cin>>n;
    ll p=quick_mod(2);
    dp[2][0]=dp[2][1]=1;
    for(int i=3;i<=n;i++)
    {
        dp[i][0]=fixll(dp[i][0]+dp[i-2][2]+dp[i-2][3]);
        dp[i][1]=fixll(dp[i][1]+dp[i-2][2]+dp[i-2][3]);
        dp[i][2]=fixll(dp[i][2]+dp[i-1][1]+dp[i-1][5]);
        dp[i][3]=fixll(dp[i][3]+dp[i-1][0]+dp[i-1][4]);
        dp[i][4]=fixll(dp[i][4]+dp[i-2][0]+dp[i-2][4]);
        dp[i][5]=fixll(dp[i][5]+dp[i-2][1]+dp[i-2][5]);
    }
    ll sum=0;
    for(int i=0;i<6;i++){
        if(i!=2&&i!=3)
        sum+=dp[n][i];
    }
    cout<<fixll(sum*p)<<endl;

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值