当前位置:网站首页>2021 Shanghai sai-d-cartland number variant, DP
2021 Shanghai sai-d-cartland number variant, DP
2022-07-25 15:33:00 【Brother Tazi is here】
The main idea of the topic :
Here you are. n n n Number , Let you divide into two rows with a length of n/2 Array of a i , b i a_i,b_i ai,bi. Then make the two arrays orderly and a i ≤ b i a_i\leq b_i ai≤bi.
n ≤ 5 e 3 n \leq 5e3 n≤5e3
Topic ideas :
If the number is different , It's a Cartland number . Duplicate number , need dp Calculation .
First consider how d p dp dp Ask for two different situations :
Convert it into a sequence of parentheses . The first row is regarded as the subscript of the left bracket , The second row shows the subscript of the right bracket .
The number of left parentheses in any prefix state shall not be less than the number of right parentheses .
such d p ( i , j ) dp(i,j) dp(i,j) For the former i Number , There are more left parentheses than right parentheses j Number of projects .
Consider the same situation : Just enumerate from small to large according to the type of number . Enumerate one more < Put several numbers on it >. When transferring, multiply by a factorial .
Because it's put like this , The two methods must correspond to different distributions of this number , So step by step multiplication , Multiply by factorial
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define fi first
#define se second
const int maxn = 5e3 + 5;
const int mod = 998244353;
int a[maxn];
ll dp[maxn][maxn] , f[maxn];
unordered_map<int,int> s;
int main()
{
f[0] = 1;
for (int i = 1 ; i < maxn ; i++)
f[i] = f[i - 1] * i % mod;
ios::sync_with_stdio(false);
int n; cin >> n;
for (int i = 1 ; i <= n ; i++){
cin >> a[i];
s[a[i]]++;
}
sort(a + 1 , a + 1 + n);
int m = unique(a + 1 , a + 1 + n) - a - 1;
dp[0][0] = 1;
for (int i = 1 ; i <= m ; i++){
for (int j = 0 ; j <= n ; j++){
int num = s[a[i]];
for (int k = 0 ; k <= num ; k++){
int l = j - 2 * k + num;
if (l < 0) continue;
dp[i][j] = (dp[i][j] + dp[i - 1][l] * f[num] % mod) % mod;
}
}
}
cout << dp[m][0] << endl;
return 0;
}
边栏推荐
- JVM-垃圾收集器详解
- Run redis on docker to start in the form of configuration file, and the connection client reports an error: server closed the connection
- window系统黑窗口redis报错20Creating Server TCP listening socket *:6379: listen: Unknown error19-07-28
- matlab 优化工具 manopt 安装
- ML - 自然语言处理 - 基础知识
- Spark submission parameters -- use of files
- JVM knowledge brain map sharing
- MySQL installation and configuration super detailed tutorial and simple database and table building method
- 看到很多App出现闪烁的图片,特别是会员页面
- pageHelper不生效,sql没有自动加上limit
猜你喜欢

Pytorch学习笔记--常用函数总结3

Remember that spark foreachpartition once led to oom

Spark partition operators partitionby, coalesce, repartition

Geogle Colab笔记1--运行Geogle云端硬盘上的.py文件

分布式原理 - 什么是分布式系统

Take you to create your first C program (recommended Collection)

wait()和sleep()的区别理解

SVD奇异值分解推导及应用与信号恢复

Spark SQL null value, Nan judgment and processing

为什么PrepareStatement性能更好更安全?
随机推荐
GAMES101复习:变换
ML - 自然语言处理 - 自然语言处理简介
How to solve the login problem after the 30 day experience period of visual stuido2019
How to understand the maximum allowable number of errors per client connection of MySQL parameters in Seata?
PAT甲级1151 LCA in a Binary Tree (30 分)
JVM parameter configuration details
ICPC2021昆明M-暴力+主席树
Implementation of asynchronous FIFO
UIDocumentInteractionController UIDocumentPickerViewController
Xcode added mobileprovision certificate file error: Xcode encoded an error
Run redis on docker to start in the form of configuration file, and the connection client reports an error: server closed the connection
Local cache --ehcache
ML - natural language processing - Basics
Phased summary of the research and development of the "library management system -" borrowing and returning "module
JVM-动态字节码技术详解
Overview of JS synchronous, asynchronous, macro task and micro task
PAT甲级1152 Google Recruitment (20 分)
Spark AQE
MySQL heap table_ MySQL memory table heap Usage Summary - Ninth Five Year Plan small pang
redis淘汰策列