当前位置:网站首页>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;
}
边栏推荐
- 元宇宙:未来我们的每一个日常行为是否都能成为赚钱工具?
- [Cloud Native--Kubernetes] Pod Controller
- SQL关联表更新
- VMware NSX 4.0 -- 网络安全虚拟化平台
- Xiaohei's leetcode journey: 95. Longest substring with at least K repeating characters
- 【LeetCode】Summary of Two Pointer Problems
- 翁恺C语言程序设计网课笔记合集
- .net(C#)获取两个日期间隔的年月日
- "Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?
- 招标公告 | 海纳百创公众号运维项目
猜你喜欢
STC89C52RC的P4口的应用问题
小黑leetcode冲浪:94. 二叉树的中序遍历
What is next-generation modeling (with learning materials)
Privacy Computing Overview
Day118. Shangyitong: order list, details, payment
2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)
10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
2022牛客暑期多校训练营5(BCDFGHK)
leetcode经典例题——单词拆分
How to automatically push my new articles to my fans (very simple, can't learn to hit me)
随机推荐
测试经理要不要做测试执行?
小黑leetcode冲浪:94. 二叉树的中序遍历
Cython
【无标题】线程三连鞭之“线程池”
招标公告 | 海纳百创公众号运维项目
[CVA Valuation Training Camp] Financial Modeling Guide - Lecture 1
Privacy Computing Overview
The role of @ Import annotations as well as how to use
Mysql_13 事务
Essential knowledge for entry-level 3D game modelers
uniapp动态实现滑动导航效果demo(整理)
【CVA估值训练营】财务建模指南——第一讲
工业物联网 —— 新型数据库的召唤
Xiaohei's leetcode journey: 95. Longest substring with at least K repeating characters
KT148A语音芯片ic工作原理以及芯片的内部架构描述
数据类型及输入输出初探(C语言)
论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》
uniapp sharing function - share to friends group chat circle of friends effect (sorting)
SQL关联表更新
Develop a SpaceX website based on the Appian low-code platform