时间限制: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^62≤n≤106) --- 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;}

venile Galant(简单dp+逆元)相关推荐

  1. Codeforces 41D Pawn 简单dp

    题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...

  2. hdu2067 简单dp或者记忆化搜索

    题意: 小兔的棋盘 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  3. POJ1088:滑雪(简单dp)

    题目链接:  http://poj.org/problem?id=1088 题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.求可以滑落的最长长度. 题目解析: 首先要先排一 ...

  4. 第三讲 数学与简单DP【完结】

    目录 1205. 买不到的数目 [数学结论题] 1211. 蚂蚁感冒 [模拟 / 推理] 1216. 饮料换购 [简单 / 模拟] 2. 01背包问题 [板子题] 1015. 摘花生 [简单DP] 8 ...

  5. hdu 2881(简单dp)

     题意:n*n的矩阵,里面有m个格子是有任务要去完成的,t,x,y表示要在第t秒到达(x,y)的格子完成任务,问你最多可以完成多少 解题思路:简单dp,将时间排个序后就是LIS #include< ...

  6. P1005 矩阵取数游戏(__int128模板/简单dp)

    转跳P1005 题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的 n \times mn×m 的矩阵,矩阵中的每个元素 a_{i,j}a i,j ​ 均为非负整数.游戏规则如下: 每次取数时 ...

  7. 最少拦截系统,简单dp,(学长说这是贪心?!。。。。。。也是醉了)

     description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天, ...

  8. HDU 1158【简单dp】

    题意:给你一个项目,需要几个月来完成买,同时也给你每个月最少需要的工人数.并且告诉你hiring,firing每个工人的钱数,以及每个月应付每个工人的工资.求项目完成时最小花费. 这是个简单dp,思路 ...

  9. HDU 6656 Kejin Player (期望DP 逆元)

    2019 杭电多校 7 1011 题目链接:HDU 6656 比赛链接:2019 Multi-University Training Contest 7 Problem Description Cub ...

最新文章

  1. SQL SERVER深入学习学习资料参考
  2. UNCTF2020 | Web Wp
  3. Command 模式 Step by Step
  4. 江湖不再平静---51CTO学院停服公告
  5. Spring框架学习笔记09:基于XML配置方式搭建SSM框架实现用户登录
  6. SoftPAC 虚拟控制器漏洞使 OT 网络易受攻击
  7. TypeScript 中的 SOLID 原则
  8. SharePoint 2013 本地创建解决方案
  9. Linux 学习笔记 (四)Ubuntu14.04 解决上网问题安装无线网卡驱动
  10. java lambda表达式详解_java8新特性-Lambda表达式的详解(从0开始)
  11. Runtime中神奇的exec方法
  12. 基于PlayTennis数据集的决策树决策分析
  13. 数字电路基础知识——锁存器与触发器在Verilog中使用问题
  14. c4d流体插件_C4D的Jet Fluids免费流体插件
  15. C++ 编译报错discards qualifiers [-fpermissive]
  16. 解决macOS邮件mail收取163邮件占用高CPU和下载不动的问题
  17. 云台山风景区:秋末冬初,走进湘中小镇的诗意时光
  18. 如何使用xposed强制开启android webview debug模式
  19. 复合选择器之后代选择器
  20. jdk9安装及java环境配置

热门文章

  1. NI-VISA写入与读写错误1073807339
  2. Java菜鸟浅谈OCR
  3. 一文读懂HTTP Caching
  4. 软考高级系统架构设计师:论分布式存储系统架构设计
  5. 常见外贸英文缩写(下)
  6. html在线ocr文字识别源码,OCR开源代码以及OCR公开训练测试数据集汇总
  7. python软件下载安装教程,如何下载和安装python
  8. 小伙伴们,一个身份证可注册五个微信公众号了!
  9. python内置函数open_Python内置函数(47)——open
  10. 欢迎使用 MWeb-Test