首页 技术 正文
技术 2022年11月9日
0 收藏 959 点赞 2,495 浏览 1543 个字

链接:https://ac.nowcoder.com/acm/contest/342/B
来源:牛客网

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

题目描述

筱玛是一个快乐的男孩子。 筱玛在一次数学考试中看到了这样一道题:

求有多少个长度为 n 的不同的排列 A,满足对于任意的 i 均有 A[A[i]] + i = n + 1。

聪明的筱玛当然一眼就秒掉了这道题,现在他想来考考你。

输入描述:

一行一个整数 n。

输出描述:

一行一个整数,表示模 998244353 意义下的答案。

示例1

输入

复制

4

输出

复制

2

说明

3 1 4 2
2 4 1 3只有以上这两个合法的排列 A。

备注:

1 ≤ n ≤ 10


 多手写(或者代码敲)几组样例,我罗列出前8组数据n  1  2  3  4  5  6  7  8  a  1  0  0  2  3  0  0  12 可以寻找出 a[i]=a[i-4]*(i-2)的规律其a[0]=a[1]= 1然后可以预处理一下,直接输出答案了。 我的AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll dp[maxn];
const ll mod=998244353ll;
ll n;int main()
{
dp[]=dp[]=1ll;
repd(i,,1e6)
{
dp[i]=dp[i-]*(i-);
dp[i]=(dp[i]+mod)%mod;
}
while(~scanf("%lld",&n))
{
printf("%lld\n",dp[n] );
}
return ;
}inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

 

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295