当前位置:网站首页>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;
}
边栏推荐
- 三、实战---爬取百度指定词条所对应的结果页面(一个简单的页面采集器)
- 导入JankStats检测卡帧库遇到问题记录
- uniapp横向选项卡(水平滚动导航栏)效果demo(整理)
- The role of @Async annotation and how to implement asynchronous listening mechanism
- leetcode经典例题——单词拆分
- Implementation principle of golang coroutine
- The role of @ Import annotations as well as how to use
- Basic web in PLSQL
- 安全软件 Avast 与赛门铁克诺顿 NortonLifeLock 合并案获英国批准,市值暴涨 43%
- .net (C#) get year month day between two dates
猜你喜欢
随机推荐
情人节---快来学习一下程序员的专属浪漫吧
jenkins send mail system configuration
Bidding Announcement | Operation and Maintenance Project of Haina Baichuang Official Account
对写作的一些感悟
安全软件 Avast 与赛门铁克诺顿 NortonLifeLock 合并案获英国批准,市值暴涨 43%
2022年华数杯数学建模
软件开发工具的技术要素
leetcode经典例题——单词拆分
Develop a SpaceX website based on the Appian low-code platform
.net(C#)获取两个日期间隔的年月日
typeScript - Partially apply a function
没有这些「伪需求」,产品经理的 KPI 怎么完成?
lua 如何 实现一个unity协程的工具
子连接中的参数传递
论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》
what is MVCC
统计单词(DAY 101)华中科技大学考研机试题
The master teaches you the 3D real-time character production process, the game modeling process sharing
What is next-generation modeling (with learning materials)
Brainstorm: Complete Backpack