当前位置:网站首页>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;
}
边栏推荐
- 2021HNCPC-E-差分,思维
- 数据系统分区设计 - 分区再平衡(rebalancing)
- UIDocumentInteractionController UIDocumentPickerViewController
- 盒子躲避鼠标
- wait()和sleep()的区别理解
- UITextField的inputView和inputAccessoryView注意点
- window系统黑窗口redis报错20Creating Server TCP listening socket *:6379: listen: Unknown error19-07-28
- Spark judges that DF is empty
- JVM parameter configuration details
- 2019陕西省省赛J-位运算+贪心
猜你喜欢
随机推荐
matlab 如何保存所有运行后的数据
Spark judges that DF is empty
Seata中jdbc下只有一个lib嘛?
PAT甲级1152 Google Recruitment (20 分)
UITextField的inputView和inputAccessoryView注意点
Find out what happened in the process of new
Flex 布局
为什么PrepareStatement性能更好更安全?
ICPC2021昆明M-暴力+主席树
SVD奇异值分解推导及应用与信号恢复
The number of query results of maxcompute SQL is limited to 1W
数据系统分区设计 - 分区与二级索引
Flex layout
p4552-差分
小波变换--dwt2 与wavedec2
自定义注解校验API参数电话号
本地缓存--Ehcache
Spark memory management mechanism new version
JVM parameter configuration details
Phased summary of the research and development of the "library management system -" borrowing and returning "module








