Peaks Gym 100365H
Peaks ( Gym 100365H )
这题nk做法还挺正常的。。后面那个循环就很恶心了
考虑 dp[i][j] 表示长度为i的排列,恰好有k个峰的方案数量。
然后转移就是把 i 插入 i-1 的排列。
i显然是i-1的排列里面最大的数,然后插入就只有两种情况:
- 插入在峰的左右,由于峰不可能相邻,所以可以插入在 2j 个位置
- 插入在爬山的时候,那么峰的数量+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的更多相关文章
- 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 ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
随机推荐
- 【UE4 插件】UnrealEnginePython 源码版编译、项目打包注意事项
源码下载 git clone git clone https://github.com/20tab/UnrealEnginePython 直接下载zip https://github.com/20ta ...
- Egg.js学习与实战系列 · Post请求`csrf token`问题
在使用axios请求egg.js封装的post接口时出现missing csrf token 或 invalid csrf token.踩过坑的新手估计不在少数,本篇记录一下解决方法. 问题原因 引用 ...
- OO第四次博客作业--第四单元总结及课程总结
一.总结第四单元两次作业的架构设计 1.1 第一次作业 类图如下: 为了突出类.接口.方法.属性.和参数之间的层次结构关系,我为 Class 和 Interface 和 Operation 分别建立了 ...
- 单片机stm32零基础入门之--初识STM32 标准库
CMSIS 标准及库层次关系 因为基于Cortex 系列芯片采用的内核都是相同的,区别主要为核外的片上外设的差异,这些差异却导致软件在同内核,不同外设的芯片上移植困难.为了解决不同的芯片厂商生产的Co ...
- linux安装后ping不通局域网其他主机的解决方式
安装了linux后尝试进行机器间的相互通讯,发现自己虚拟机并不能查看ip地址,也不能够ping通任何一台局域网内的主机 上网查了一下发现是网卡并没有打开,需要进行如下配置 查看ls 一下/etc/sy ...
- 文件上传漏洞Bypass总结
文件上传漏洞Bypass总结 前端JS验证文件类型: 上传后缀jpg,抓包改为php后缀 ======================================================= ...
- Hadoop的HA(ZooKeeper)安装与部署
非HA的安装步骤 https://www.cnblogs.com/live41/p/15467263.html 一.部署设定 1.服务器 c1 192.168.100.105 zk.name ...
- advanced base-scripting guide in chinese(高级Bash脚本编程指南-10)
<高级Bash脚本编程指南>Revision 10中文版 github上链接地址: https://github.com/LinuxStory/Advanced-Bash-Scriptin ...
- linux下文件特殊权限设置位S和沾附位T(转载)
今天在创建文件的时候,发现了文件权限末尾有个T,之前没留意过,后来又用c创建(open)了两个文件来查看,在我没有指定权限(省略open的第三个参数)的时候,有时还会出现S,虽然还没弄懂什么时候会出现 ...
- switch中case...用法-c语言
... 表示范围 case 0...4; // error case 5 ... 9; // ok eg 1: char ch = 4; switch(ch) { case 1: printf(& ...