BZOJ 5161: 最长上升子序列 状压dp+查分
好神啊 ~
打表程序:
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 140000000
#define ll long long
#define mod 998244353
#define setIO(s) freopen(s".in","r",stdin) , freopen(s".out","w",stdout)
using namespace std;
int f[2][N];
int cnt[N];
ll qpow(ll x,ll y) {
ll ans=1;
while(y) {
if(y&1) {
ans=ans*x%mod;
}
x=x*x%mod;
y>>=1;
}
return ans;
}
int main() {
// setIO("input");
for(int n=1;n<=30;n+=2) {
int i,j,k,d,t,pos;
ll ans=0,fac=1;
--n;
f[0][0]=1;
for(d=i=1;i<=n;++i,d^=1) {
memset(f[d],0,sizeof(int)*(1<<i));
for(j=0;j<(1<<(i-1));++j) {
f[d][j<<1]=(f[d][j<<1]+f[d^1][j])%mod,pos=-1;
for(k=i-1;k>=0;--k) {
t=((j>>k)<<(k+1))|(1<<k)|(j&((1<<k)-1));
if(j&(1<<k)) pos=k; // 这里有一
if(pos>=0) t^=(1<<(pos+1));
f[d][t]=(f[d][t]+f[d^1][j])%mod;
}
}
}
for(i=1;i<(1<<n);++i) {
cnt[i]=cnt[i-(i&-i)]+1;
}
for(i=0;i<(1<<n);++i) {
ans=(ans+1ll*f[n&1][i]*(cnt[i]+1))%mod;
}
for(i=1;i<=n+1;++i) {
fac=fac*i%mod;
}
printf("%lld\n",ans*qpow(fac,mod-2)%mod);
}
return 0;
}
表:
#include <cstdio>
int ans[40]={
1,
499122178,
2,
915057326,
540715694,
946945688,
422867403,
451091574,
317868537,
200489273,
976705134,
705376344,
662845575,
331522185,
228644314,
262819964,
686801362,
495111839,
947040129,
414835038,
696340671,
749077581,
301075008,
314644758,
102117126,
819818153,
273498600,
267588741,
};
int main() {
int n;
scanf("%d",&n);
printf("%d\n",ans[n-1]);
return 0;
}
BZOJ 5161: 最长上升子序列 状压dp+查分的更多相关文章
- BZOJ.3591.最长上升子序列(状压DP)
BZOJ 题意:给出\(1\sim n\)的一个排列的一个最长上升子序列,求原排列可能的种类数. \(n\leq 15\). \(n\)很小,参照HDU 4352这道题,我们直接把求\(LIS\)时的 ...
- 【bzoj5161】最长上升子序列 状压dp+打表
题目描述 现在有一个长度为n的随机排列,求它的最长上升子序列长度的期望. 为了避免精度误差,你只需要输出答案模998244353的余数. 输入 输入只包含一个正整数n.N<=28 输出 输出只包 ...
- bzoj5161 最长上升子序列 状压DP(DP 套 DP) + 打表
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=5161 题解 回顾一下以前用二分求 LIS 的方法:令 \(f[i]\) 表示长度为 \(i\) ...
- [BZOJ 1072] [SCOI2007] 排列perm 【状压DP】
题目链接:BZOJ 1072 这道题使用 C++ STL 的 next_permutation() 函数直接暴力就可以AC .(使用 Set 判断是否重复) 代码如下: #include <io ...
- BZOJ 3195 [Jxoi2012]奇怪的道路 | 状压DP
传送门 BZOJ 3195 题解 这是一道画风正常的状压DP题. 可以想到,\(dp[i][j][k]\)表示到第\(i\)个点.已经连了\(j\)条边,当前\([i - K, i]\)区间内的点的度 ...
- BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3336 Solved: 1936[Submit][ ...
- BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )
水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ------------------- ...
- BZOJ 2734 [HNOI2012]集合选数 (状压DP、时间复杂度分析)
题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2734 题解 嗯早就想写的题,昨天因为某些不可告人的原因(大雾)把这题写了,今天再来写题解 ...
- BZOJ.4160.[NEERC2009]Exclusive Access 2(状压DP Dilworth定理)
BZOJ DAG中,根据\(Dilworth\)定理,有 \(最长反链=最小链覆盖\),也有 \(最长链=最小反链划分数-1\)(这个是指最短的最长链?并不是很确定=-=),即把所有点划分成最少的集合 ...
随机推荐
- Distributed and Parallel Computing
Omega Network Model
- 探索FFmpeg
Part1 :FFmpeg简介 FFmpeg定义 FFmpeg是一款音视频编解码工具,为开发者提供了大量音视频处理接口. FF指的是"Fast Forward" FFmpeg历史 ...
- 2018 ACM-ICPC徐州站网络赛 G题
There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xxx , yy ...
- UVA 10924 Prime Words 题解
Prime Words A prime number is a number that has only two divisors: itself and the number one. Exampl ...
- Phaser铁人三项
/** * 模拟铁人三项 */ public class PhaserTest { private static Random random = new Random(System.currentTi ...
- Sentry异常捕获平台
本文包括Sentry平台的介绍,以及环境搭建两部分,更多细节请查阅官方文档. 简介 Sentry是一个实时事件的日志聚合平台.它专门监测错误并提取所有有用信息用于分析,不再麻烦地依赖用户反馈来定位问题 ...
- 在ubuntu下安装openjdk
OpenJDK是JDK的开放源码版本,以GPL(General Public License,通用性公开许可证)协议的形式放出.因为授权协议的原因,Sun公司实现的JDK的一部分源码因为产权的问题无法 ...
- 【转】Redis 分布式锁的正确实现方式( Java 版 )
链接:wudashan.cn/2017/10/23/Redis-Distributed-Lock-Implement/ 前言 分布式锁一般有三种实现方式:1. 数据库乐观锁:2. 基于Redis的分布 ...
- 第一个APP上架IOS审核相关的记录
以前一直没做过APP开发,第一版是用WAP版做的,采用了light7框架制作,没有UI设计. 升级到第二版之后,使用了HBUILDER的方式开发,https://dcloud.io/ 官方在这里. 目 ...
- 13、VUE单文件工程
1.为什么要使用单文件工程? 1.Vue.js路由组件的不方便 不支持引用HTML页面,以至于template里面定义的标签会编辑器当字符串,这让编辑变的困难. 2.Vue.js于Node.js语言结 ...