当前位置:网站首页>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;
}
边栏推荐
- 矩阵数学原理
- Senior game modelers tell newbies, what are the necessary software for game scene modelers?
- Statistical words (DAY 101) Huazhong University of Science and Technology postgraduate examination questions
- mysql基础
- 情侣牵手[贪心 & 抽象]
- 4 - "PyTorch Deep Learning Practice" - Backpropagation
- 学会反射后,我被录取了(干货)
- 【LeetCode】Summary of Two Pointer Problems
- Ab3d.PowerToys and Ab3d.DXEngine Crack
- KT6368A Bluetooth certification problem_FCC and BQB_CE_KC certification or other instructions
猜你喜欢

看图识字,DELL SC4020 / SCv2000 控制器更换过程

leetcode经典例题——单词拆分

什么是次世代建模(附学习资料)

小黑leetcode之旅:95. 至少有 K 个重复字符的最长子串

Mysql_13 事务
![Couple Holding Hands [Greedy & Abstract]](/img/7d/1cafc000dc58f1c5e2e92150be7953.png)
Couple Holding Hands [Greedy & Abstract]

Day118. Shangyitong: order list, details, payment

Essential knowledge for entry-level 3D game modelers

The master teaches you the 3D real-time character production process, the game modeling process sharing

三、实战---爬取百度指定词条所对应的结果页面(一个简单的页面采集器)
随机推荐
统计单词(DAY 101)华中科技大学考研机试题
Handwritten Distributed Configuration Center (1)
MAUI Blazor 权限经验分享 (定位,使用相机)
导入JankStats检测卡帧库遇到问题记录
入门3D游戏建模师知识必备
typeScript - Partially apply a function
Flutter启动流程(Skia引擎)介绍与使用
Privacy Computing Overview
[LeetCode] Summary of Matrix Simulation Related Topics
Essential knowledge for entry-level 3D game modelers
Basic web in PLSQL
【CVA估值训练营】财务建模指南——第一讲
00、数组及字符串常用的 API(详细剖析)
ARC129E Yet Another Minimization 题解 【网络流笔记】
LeetCode Hot 100
论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》
一、爬虫基本概念
对写作的一些感悟
SQL association table update
【云原生--Kubernetes】调度约束