当前位置:网站首页>D - I Hate Non-integer Number (选数的计数dp
D - I Hate Non-integer Number (选数的计数dp
2022-08-05 00:08:00 【__Rain】
D - I Hate Non-integer Number
思路:
枚举选 l l l 个数,然后 d p [ i ] [ j ] [ k ] dp[i][j][k] dp[i][j][k] 表示前 i i i 个数选 j j j 个数 % l \%l %l 的和为 k k k 的方案数
那么答案就是所有 l l l 情况下的 d p [ n ] [ l ] [ 0 ] dp[n][l][0] dp[n][l][0] 的加和
code:
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define ld long double
#define all(x) x.begin(), x.end()
#define mem(x, d) memset(x, d, sizeof(x))
#define eps 1e-6
using namespace std;
const int maxn = 2e6 + 9;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll n, m;
int a[109];
ll dp[109][109][109];
// 前i个数选j个,和 %l 为 k 的方案数
ll ans = 0;
void work()
{
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
}
for(int l = 1; l <= n; ++l)
{
mem(dp, 0);
dp[0][0][0] = 1;
for(int i = 1; i <= n; ++i){
for(int j = 0; j <= i; ++j)
for(int k = 0; k < l; ++k)
dp[i][j][k] = dp[i-1][j][k];// 先把不选a_i的情况转移一下
for(int j = 0; j <= i; ++j){
for(int k = 0; k < l; ++k){
if(j >= 1){
int sum = (a[i] + k) % l;
(dp[i][j][sum] += dp[i-1][j-1][k]) %= mod;
}
}
}
}
(ans += dp[n][l][0]) %= mod;
}
cout << ans;
}
int main()
{
ios::sync_with_stdio(0);
// int TT;cin>>TT;while(TT--)
work();
return 0;
}
边栏推荐
- The role of the annotation @ EnableAutoConfiguration and how to use
- Mysql based
- 美团二面:Redis与MySQL双写一致性如何保证?
- Some thoughts on writing
- LeetCode Hot 100
- 【LeetCode】Summary of Two Pointer Problems
- 【LeetCode】滑动窗口题解汇总
- 【手撕AHB-APB Bridge】~ AMBA总线 之 AHB
- 【云原生--Kubernetes】Pod控制器
- Three tips for you to successfully get started with 3D modeling
猜你喜欢
随机推荐
隐私计算综述
什么是次世代建模(附学习资料)
【数据挖掘概论】数据挖掘的简单描述
jenkins发送邮件系统配置
ARC129E Yet Another Minimization 题解 【网络流笔记】
RK3399平台开发系列讲解(内核调试篇)2.50、嵌入式产品启动速度优化
Senior game modelers tell newbies, what are the necessary software for game scene modelers?
3. Actual combat---crawl the result page corresponding to Baidu's specified entry (a simple page collector)
再肝3天,整理了90个 NumPy 例子,不能不收藏!
中日颜色风格
2022年华数杯数学建模
Day118. Shangyitong: order list, details, payment
what?测试/开发程序员要被淘汰了?年龄40被砍到了32?一瞬间,有点缓不过神来......
Mysql_14 存储引擎
2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)
2022年华数杯数学建模
[CVA Valuation Training Camp] Financial Modeling Guide - Lecture 1
【LeetCode】图解 904. 水果成篮
【无标题】
日志(logging模块)








