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 ...
随机推荐
- F1英国大奖赛-银石赛道地图及弯道
背景 今天晚上(2020-08-02)是今年英国大奖赛的正赛.刚好了解了一下赛道地图.记录一下,明年就不用到处找了. 简介 银石赛道(Silverstone Circuit)由一个废弃的空军基地改建, ...
- PyCharm永久破解方法,2021最新版本!!!
1,下载破解补丁(已更新到2021.1版本): 关注微信公众号<程序员的时光>,回复破解补丁即可: 下载补丁文件 jetbrains-agent.jar 和importat.txt文件并将 ...
- 【UE4 C++】 Config Settings配置文件(.ini)
简介 常见存储路径 \Engine\Config\ \Engine\Saved\Config\ (运行后生成) [ProjectName]\Config\ [ProjectName]\Saved\Co ...
- Jmeter之BeanShell 断言
作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15436864.html 博客主页:https://www.cnblogs.com/testero ...
- 如何从一台OPC Server访问多个PLC
项目中遇到如下情况: 1. 整条生产线由多个PLC分别控制,但是所有PLC在同一个局域网内.PLC采用西门子的S7-200 Smart 2. 客户希望在操作工站的电脑(跟PLC在同一个局域网内)上提供 ...
- Java:ConcurrentHashMap类小记-1(概述)
Java:ConcurrentHashMap类小记-1(概述) 对 Java 中的 ConcurrentHashMap类,做一个微不足道的小小小小记,分三篇博客: Java:ConcurrentHas ...
- [no code][scrum meeting] Alpha 12
项目 内容 会议时间 2020-04-19 会议主题 周总结会议 会议时长 45min 参会人员 全体成员 $( "#cnblogs_post_body" ).catalog() ...
- mybatis自定义分页拦截器
最近看了一下项目中代码,发现系统中使用的mybatis分页使用的是mybatis自带的分页,即使用RowBounds来进行分页,而这种分页是基于内存分页,即一次查出所有的数据,然后再返回分页需要的数据 ...
- Java 将Word保存为WPS和WPT格式
本文通过Java示例展示将Word文档(如.doc/.docx)保存为WPS和WPT格式的方法. 程序环境配置 IntelliJ IDEA 2018(jdk 1.8.0) Word Jar包:Spir ...
- Noip模拟13 2021.7.13:再刚题,就剁手&&生日祭
T1 工业题 这波行列看反就非常尴尬.....口糊出所有正解想到的唯独行列看反全盘炸列(因为和T1斗智斗勇两个半小时...) 这题就是肯定是个O(n+m)的,那就往哪里想,a,b和前面的系数分开求,前 ...