Cyclic

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 193    Accepted Submission(s): 125

Problem Description
Count the number of cyclic permutations of length n with no continuous subsequence [i, i + 1 mod n].
Output the answer modulo 998244353.
 
Input
The first line of the input contains an integer T , denoting the number of test cases.
In each test case, there is a single integer n in one line, denoting the length of cyclic permutations.
1 ≤ T ≤ 20, 1 ≤ n ≤ 100000
 
Output
For each test case, output one line contains a single integer, denoting the answer modulo 998244353.
 
Sample Input
3
4
5
6
 
Sample Output
1
8
36
 

题意:求满足一个方向的(a[i]+1)%n!=a[i+1]循环数列的n个数字组成的数列的可能性

分析:首先按照题目的意思做一个全排列列出前面几项的可能数

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
const ll mod = 998244353;
const double pi = acos(-1.0);
const double eps = 1e-8;
ll a[maxn];
int main() {
ios::sync_with_stdio(0);
ll T, n;
scanf("%lld",&T);
while( T -- ) {
scanf("%lld",&n);
for( ll i = 0; i < n; i ++ ) {
a[i] = i+1;
}
ll cnt = 0;
while(next_permutation(a,a+n)) {
bool flag = true;
for( ll i = 0; i < n-1; i ++ ) {
ll t;
if( (a[i]+1)%n == 0 ) {
t = a[i]+1;
} else {
t = (a[i]+1)%n;
}
if( t == a[i+1] ) {
flag = false;
break;
}
}
ll t;
if( (a[n-1]+1)%n == 0 ) {
t = a[n-1]+1;
} else {
t = (a[n-1]+1)%n;
}
if( t == a[0] ) {
flag = false;
}
if(flag) {
cnt ++;
/*for( ll i = 0; i < n; i ++ ) {
cout << a[i] << " ";
}
cout << endl;*/
}
}
printf("%lld\n",cnt/n);
}
return 0;
}

  接着找规律

AC代码:

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10;
const ll mod = 998244353;
const double pi = acos(-1.0);
const double eps = 1e-8;
ll a[maxn];
int main() {
ios::sync_with_stdio(0);
ll T, n;
a[1] = 0, a[2] = 0, a[3] = 0, a[4] = 1, a[5] = 8, a[6] = 36;
for( ll i = 7; i <= maxn-10; i ++ ) {
a[i] = ((i-3)*a[i-1]%mod+(i-2)*(2*a[i-2]+a[i-3])%mod)%mod;
}
scanf("%lld",&T);
while( T -- ) {
scanf("%lld",&n);
printf("%lld\n",a[n]);
}
return 0;
}

  

杭电多校第十场 hdu6432 Cyclic 打表找规律的更多相关文章

  1. 杭电多校第十场 hdu6435 CSGO 二进制枚举子集

    CSGO Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Subm ...

  2. 杭电多校第十场 hdu6434 Count 欧拉函数打表 快速打表模板

    Problem I. Count Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

  3. Make Rounddog Happy(2019年杭电多校第十场1011+HDU6701+启发式分治)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 求有多少个子区间满足\(a_l,a_{l+1},\dots,a_r\)均不相同且\(max(a_l,a_{l+1},\dots,a_r)-(r ...

  4. [2019杭电多校第十场][hdu6701]Make Rounddog Happy

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6701 题目大意为求满足 $max(a_{l},a_{l+1}\cdot \cdot \cdot a_{ ...

  5. 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)

    以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...

  6. 2018杭电多校第三场1003(状态压缩DP)

    #include<bits/stdc++.h>using namespace std;const int mod =1e9+7;int dp[1<<10];int cnt[1& ...

  7. HDU 5745 La Vie en rose (DP||模拟) 2016杭电多校联合第二场

    题目:传送门. 这是一道阅读理解题,正解是DP,实际上模拟就能做.pij+1 指的是 (pij)+1不是 pi(j+1),判断能否交换输出即可. #include <iostream> # ...

  8. HDU 5744 Keep On Movin (贪心) 2016杭电多校联合第二场

    题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream ...

  9. HDU 5742 It's All In The Mind (贪心) 2016杭电多校联合第二场

    题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> ...

随机推荐

  1. git开发流程

    典型的工作流程和做法是,由于你没有远程仓库的权限,你先在github通过fork,复制自己的一份远程仓库,然后通过clone你自己这个远程副本到本地,进行修改,修改后push到自己的githu远程副本 ...

  2. [nghttp2]压测工具,源码编译并进行deb打包过程

    编译环境:deepin 15.11桌面版 nghttp2下载地址:https://github.com/nghttp2/nghttp2 环境要求 emm只能在类Linux环境才能完整编译,想在Wind ...

  3. 【JDK】JDK源码分析-CountDownLatch

    概述 CountDownLatch 是并发包中的一个工具类,它的典型应用场景为:一个线程等待几个线程执行,待这几个线程结束后,该线程再继续执行. 简单起见,可以把它理解为一个倒数的计数器:初始值为线程 ...

  4. Go包管理工具dep

    dep是一个golang依赖管理工具,需要在Go 1.7及更高的版本中使用. 1. 安装 安装dep工具的方式有很多种,如果是mac电脑的话,只需要如下命令: brew install dep 对于L ...

  5. 1.1Django简介和虚拟环境配置

    MVC 大部分开发语言中都有MVC框架 MVC框架的核心思想是:解耦 降低各功能模块之间的耦合性,方便变更,更容易重构代码,最大程度上实现代码的重用 m表示model,主要用于对数据库层的封装 v表示 ...

  6. 爬虫之爬取电影天堂(request)

    #需要通过代码打开https://www.dytt8.net/网站,拿到网站内容 from urllib.request import urlopen #拿到urlopen import re con ...

  7. testlink搭建教程

    1,下载testlink安装包   请加QQ群299524235,在群文件中下载     2.配置Apache环境和PHP环境   解压testlink文件到Apache中, 通过127.0.0.1/ ...

  8. 转载:hive分区(partiton)简介

    网上有篇关于hive的partition的使用讲解的比较好,所以转载了.原文https://blog.csdn.net/akon_vm/article/details/37832511 一.背景 1. ...

  9. c# 将dwg文件转化为pdf

    https://blog.csdn.net/mywaster/article/details/50220379 最近做一个项目,要求将dwg文件转化为pdf,开发工具VS2010 + AutoCad ...

  10. 微信小程序商城系统怎样搭建?

    微信是一种非常便捷的生活方式,微信小程序一直深受企业和商家的青睐,如美团.京东.拼多多.唯品会.小红书等知名公司都推出了自己的小程序.对于网上商城小程序的开发似乎是一件非常难的事情,用什么开发?如何开 ...