当前位置:网站首页>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;
}
边栏推荐
- 死锁杂谈
- ML - 语音 - 高级语音模型
- Pytorch学习笔记--常用函数总结3
- Distributed principle - what is a distributed system
- 2021上海市赛-H-二分答案
- C language function review (pass value and address [binary search], recursion [factorial, Hanoi Tower, etc.))
- Spark DF adds a column
- 数据系统分区设计 - 分区再平衡(rebalancing)
- Idea eye care settings
- Node learning
猜你喜欢

Pytorch学习笔记-Advanced_CNN(Using Inception_Module)实现Mnist数据集分类-(注释及结果)

Reflection - Notes

ML - natural language processing - Key Technologies

Application of C language array in Sanzi chess -- prototype of Queen n problem

你准备好脱离“内卷化怪圈”了吗?

Idea eye care settings

No tracked branch configured for branch xxx or the branch doesn‘t exist. To make your branch trac

MATLAB读取显示图像时数据格式转换原因

异步fifo的实现

Understanding the execution order of T-SQL query from the execution order of join on and where
随机推荐
Singleton mode 3-- singleton mode
分布式原理 - 什么是分布式系统
ML - 自然语言处理 - 基础知识
GAMES101复习:三维变换
See a lot of blinking pictures on apps, especially the member page
Iframe nested other website page full screen settings
Spark SQL UDF function
带你详细认识JS基础语法(建议收藏)
pageHelper不生效,sql没有自动加上limit
为什么PrepareStatement性能更好更安全?
matlab 优化工具 manopt 安装
2021HNCPC-E-差分,思维
2016CCPC网络选拔赛C-换根dp好题
自定义注解校验API参数电话号
C#精挑整理知识要点11 委托和事件(建议收藏)
Instance tunnel use
JVM-垃圾收集器详解
How to solve the problem of scanf compilation error in Visual Studio
CF888G-巧妙字典树+暴力分治(异或最小生成树)
JVM garbage collector details