Peaks ( Gym 100365H )

这题nk做法还挺正常的。。后面那个循环就很恶心了

考虑 dp[i][j] 表示长度为i的排列,恰好有k个峰的方案数量。

然后转移就是把 i 插入 i-1 的排列。

i显然是i-1的排列里面最大的数,然后插入就只有两种情况:

  1. 插入在峰的左右,由于峰不可能相邻,所以可以插入在 2j 个位置
  2. 插入在爬山的时候,那么峰的数量+1

$ dp[i][j] = 2j\times dp[i-1][j] + ( i - 2(j - 1) )dp[i-1][j-1] $

其实,由于 j 只有 30 , 可以矩阵快速幂,大概是 $ k^3( mod + log n ) $

但是发现把矩阵写出来可以有这么个神仙结论 $ f( n , k ) = f( n + 56882 , k ) (\mod 239 ) $

暴力暴力

别忘了这题开文件

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
#define int long long
typedef long long ll;
#define MAXN 57000
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define inf 0x3f3f3f3f
#define cmx( a , b ) a = max( a , b )
#define cmn( a , b ) a = min( a , b )
#define P 239
void read( signed& x ) {
scanf("%d",&x);
}
void read( ll& x ) {
scanf("%lld",&x);
}
int n , k;
int dp[MAXN][31];
signed main() {
freopen("peaks.in","r",stdin);
freopen("peaks.out","w",stdout);
cin >> n >> k;
n %= 56882;
dp[0][0] = 1;
for( int i = 1 ; i <= n ; ++ i )
for( int j = 1 ; j <= k ; ++ j )
dp[i][j] = ( 2 * j * dp[i - 1][j] % P + ( i - 2 * ( j - 1 ) + P ) % P * dp[i - 1][j - 1] % P ) % P;
printf("%d\n",dp[n][k]);
}
/*
* Things you should pay attention to
* inf is big enough?
* out of bounds?
* long long ?
*/

Peaks Gym 100365H的更多相关文章

  1. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  2. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  3. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  4. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  5. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  6. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  7. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  8. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

  9. Gym 101102C---Bored Judge(区间最大值)

    题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...

随机推荐

  1. 性能利器 Takin 来了!首个生产环境全链路压测平台正式开源

    6 月 25 日,国内知名的系统高可用专家数列科技宣布开源旗下核心产品能力,对外开放生产全链路压测平台产品的源代码,并正式命名为 Takin. 目前中国人寿.顺丰科技.希音.中通快递.中国移动.永辉超 ...

  2. Noip模拟79 2021.10.17(题目名字一样)

    T1 F 缩点缩成个$DAG$,然后根据每个点的度数计算期望值 1 #include<cstdio> 2 #include<cstring> 3 #include<vec ...

  3. Noip模拟18 2021.7.17 (文化课专场)

    T1 导弹袭击(数学) 显然,我们要找到最优的A,B使得一组a,b优于其他组那么可以列出: $\frac{A}{a_i}+\frac{B}{b_i}<\frac{A}{a_j}+\frac{B} ...

  4. OpenWrt编译问题记录

    错误一.config.status: error: cannot find input file: `xmetadataretriever/Makefile.in' configure: creati ...

  5. 转移指令原理和Inline Hook

    目录 转移指令原理和Inline Hook 转移指令 操作符offset jmp指令 根据位移进行转移的jmp指令 插播HOOK知识 Inline Hook Inline Hook 原理 Hook代码 ...

  6. vue打包后反编译到源代码(reverse-sourcemap)

    因为突然的疫情把我困在家了,家里的电脑没有源代码,但是需求还要改,工作还得继续... 从服务器下载了之前上传的打包后的文件,找了一圈反编译方法,得救了,在此记录一下. 1.npm install -- ...

  7. (三)FastDFS 高可用集群架构学习---Client 接口开发

    一.Python3 与 FastDFS 交互 1.安装 py3fdfs模块 # pip3 install py3Fdfs 2.测试使用 py3Fdfs 与 Fastdfs 集群交互(上传文件) fro ...

  8. 【python】以souhu邮箱为例学习DDT数据驱动测试

    前言 DDT(Data-Driven Tests)是针对 unittest 单元测试框架设计的扩展库.允许使用不同的测试数据来运行一个测试用例,并将其展示为多个测试用例.通俗理解为相同的测试脚本使用不 ...

  9. 【Java】数组Array

    Java基础复习之:数组 简介 数组(Array):多个相同数据类型按照一定顺序排列的集合,并使用一个名字命名,通过编号的方式对这些数据进行统一管理 一维数组 一维数组的声明与初始化 int[] id ...

  10. 子查询之 exists 和 in

    exists exists用于检查一个子查询是否至少会返回一行数据(即检测行的存在),返回值为boolean型,true或false 语法 exists subquery /* 参数: subquer ...