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. 【UE4 C++】UObject 创建、销毁、内存管理

    UObject 的创建 NewObject 模板类 本例使用 UE 4.26,只剩下 NewObject 用来创建 UObject,提供两个带不同可选参数构造函数的模板类 Outer 表示这个对象的外 ...

  2. Java:创建对象小记

    Java:创建对象小记 对 Java 中的创建对象的内容,做一个微不足道的小小小小记 创建对象的方式概述 使用 new 关键字:Person person = new Person(); 反射创建:使 ...

  3. 机器学习:EM算法

    EM算法 各类估计 最大似然估计 Maximum Likelihood Estimation,最大似然估计,即利用已知的样本结果,反推最有可能(最大概率)导致这样结果的参数值的计算过程. 直白来讲,就 ...

  4. makedown笔记

    makedown语法 表格 这个表格的主题 |姓名|性别|年龄|职业| | ----- | ----- | ----- | ----- | |张三|男|34|码农| |李四|男|27|代驾| 这个表格 ...

  5. spring cloud ribbon的使用

    上节我们学会了如何搭建一个eureka server服务,本节我们使用ribbon来实现服务间的调用. 前置条件: 1.创建几个工程 eureka-server             |- 服务注册 ...

  6. SpringCloud+RocketMQ实现分布式事务

    随着互联网公司的微服务越来越多,分布式事务已经成为了我们的经常使用的.所以我们来一步一步的实现基于RocketMQ的分布式事务.接下来,我们将要做的主题写出来. RocketMQ的分布式事务结构和说明 ...

  7. C语言零基础入门难发愁,那就快来看看这篇基础整理资料吧

    C语言程序的结构认识 用一个简单的c程序例子,介绍c语言的基本构成.格式.以及良好的书写风格,使小伙伴对c语言有个初步认识. 例1:计算两个整数之和的c程序: #include main() { in ...

  8. 21.7.1 test

    \(NOI\) 模拟赛 呜呜呜 \(\cdots\cdots\) \(T1\) 类似哈夫曼编码,虽然没学过但是我依然画出了二叉树,然后尝试树形dp,并且最后还抓住了一个优化!让我兴奋地以为自己能赛时A ...

  9. TCP 拥塞窗口原理

    学过网络相关课程的,都知道TCP中,有两个窗口: 滑动窗口(在我们的上一篇文章中有讲),接收方通过通告发送方自己的可以接受缓冲区大小(这个字段越大说明网络吞吐量越高),从而控制发送方的发送速度. 拥塞 ...

  10. Java设计模式——模板设计模式

    模板设计模式 1.模板模式简介 模板模式(Template ):模板方法模式是类的行为模式.准备一个抽象类,将部分逻辑以具体方法以及具体构造函数的形式实现,然后声明一些抽象方法来迫使子类实现剩余的逻辑 ...