当前位置:网站首页>D - I Hate Non-integer Number (count of selected number dp
D - I Hate Non-integer Number (count of selected number dp
2022-08-05 00:21: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];// don't choosea_iShift the situation
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;
}
边栏推荐
猜你喜欢
随机推荐
00、数组及字符串常用的 API(详细剖析)
D - I Hate Non-integer Number (选数的计数dp
软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?
The applicable scenarios and common product types of the KT148A electronic voice chip ic solution
在线中文姓名生成工具推荐
The master teaches you the 3D real-time character production process, the game modeling process sharing
软件测试面试题:做好测试计划的关键是什么?
ansible学习笔记分享-含剧本示例
Some thoughts on writing
关于使用read table 语句
node uses redis
电赛必备技能___定时ADC+DMA+串口通信
软件测试面试题:什么是软件测试?软件测试的目的与原则?
2022 Hangzhou Electric Multi-School Training Session 3 1009 Package Delivery
软件测试面试题:软件都有多少种分类?
2022杭电多校训练第三场 1009 Package Delivery
Three tips for you to successfully get started with 3D modeling
tiup update
Mysql_13 事务
"Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?

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



![[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots](/img/fa/5bdc81b1ebfc22d31f42da34427f3e.png)



