当前位置:网站首页>abc262-D(dp)
abc262-D(dp)
2022-08-05 10:28:00 【一条小小yu】
D - I Hate Non-integer Number Editorial

/
Time Limit: 2.5 sec / Memory Limit: 1024 MB
Score : 400400 points
Problem Statement
You are given a sequence of positive integers A=(a_1,\ldots,a_N)A=(a1,…,aN) of length NN.
There are (2^N-1)(2N−1) ways to choose one or more terms of AA. How many of them have an integer-valued average? Find the count modulo 998244353998244353.
Constraints
- 1 \leq N \leq 1001≤N≤100
- 1 \leq a_i \leq 10^91≤ai≤109
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
NN a_1a1 \ldots… a_NaN
Output
Print the answer.
Sample Input 1 Copy
Copy
3 2 6 2
Sample Output 1 Copy
Copy
6
For each way to choose terms of AA, the average is obtained as follows:
If just a_1a1 is chosen, the average is \frac{a_1}{1}=\frac{2}{1} = 21a1=12=2, which is an integer.
If just a_2a2 is chosen, the average is \frac{a_2}{1}=\frac{6}{1} = 61a2=16=6, which is an integer.
If just a_3a3 is chosen, the average is \frac{a_3}{1}=\frac{2}{1} = 21a3=12=2, which is an integer.
If a_1a1 and a_2a2 are chosen, the average is \frac{a_1+a_2}{2}=\frac{2+6}{2} = 42a1+a2=22+6=4, which is an integer.
If a_1a1 and a_3a3 are chosen, the average is \frac{a_1+a_3}{2}=\frac{2+2}{2} = 22a1+a3=22+2=2, which is an integer.
If a_2a2 and a_3a3 are chosen, the average is \frac{a_2+a_3}{2}=\frac{6+2}{2} = 42a2+a3=26+2=4, which is an integer.
If a_1a1, a_2a2, and a_3a3 are chosen, the average is \frac{a_1+a_2+a_3}{3}=\frac{2+6+2}{3} = \frac{10}{3}3a1+a2+a3=32+6+2=310, which is not an integer.
Therefore, 66 ways satisfy the condition.
Sample Input 2 Copy
Copy
5 5 5 5 5 5
Sample Output 2 Copy
Copy
31
Regardless of the choice of one or more terms of AA, the average equals 55.
#include<bits/stdc++.h>
using namespace std;
const int MAXN =1e2 + 10;
const int MOD = 998244353;
long long a[MAXN],n,ans,dp[MAXN][MAXN][MAXN];
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
for(int s = 1; s <= n; s++)
{
memset(dp,0,sizeof dp);
dp[0][0][0] = 1;
for(int i = 0; i < n; i++)
{
for(int j = 0; j <= s && j <= i; j++)
{
for(int k = 0; k < s; k++)
{
dp[i + 1][j][k] += dp[i][j][k];
dp[i + 1][j][k] %= MOD;
if(j != s)dp[i + 1][j + 1][(k + a[i + 1]) % s] += dp[i][j][k];
dp[i + 1][j + 1][(k + a[i + 1]) % s] %= MOD;
}
}
}
ans += dp[n][s][0];
ans %= MOD;
}
cout << ans;
}
边栏推荐
- Introduction to SD NAND Flash!
- Our Web3 Entrepreneurship Project, Yellow
- E-sports, convenience, efficiency, security, key words for OriginOS functions
- 19.3 restart the Oracle environment
- PCB layout must know: teach you to correctly lay out the circuit board of the op amp
- 第四章:activiti RuntimeService设置获和取流程变量,及与taskService的区别,开始和完成任务时设置流程变量[通俗易懂]
- 第八章:activiti多用户任务分配
- STM32+ULN2003 drives 28BYJ4 stepper motor (forward and reverse according to the number of turns)
- 还在找网盘资源吗?快点收藏如下几个值得收藏的网盘资源搜索神器吧!
- 2022 Hangzhou Electric Power Multi-School Session 6 1008.Shinobu Loves Segment Tree Regular Questions
猜你喜欢

three.js debugging tool dat.gui use

JS逆向入门学习之回收商网,手机号码简易加密解析

NowCoderTOP35-40 - continuous update ing

JS introduction to reverse the recycling business network of learning, simple encryption mobile phone number

【 temperature warning program DE development 】 event driven model instance

Login function and logout function (St. Regis Takeaway)

阿里顶级架构师多年总结的JVM宝典,哪里不会查哪里!

The host computer develops C# language: simulates the STC serial port assistant to receive the data sent by the microcontroller

用KUSTO查询语句(KQL)在Azure Data Explorer Database上查询LOG实战

PCB layout must know: teach you to correctly lay out the circuit board of the op amp
随机推荐
RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
The query that the user's test score is greater than the average score of a single subject
PCB layout must know: teach you to correctly lay out the circuit board of the op amp
FPGA: Basic Getting Started LED Lights Blinking
【翻译】混沌网+SkyWalking:为混沌工程提供更好的可观察性
数据可视化(二)
秘乐短视频挖矿系统开发详情
攻防世界-PWN-new_easypwn
Chapter 5: Multithreaded Communication—wait and notify
NowCoderTOP35-40 - continuous update ing
第七章,activiti个人任务分配,动态指定和监听器指定任务委派人「建议收藏」
第四章:redis 数组结构的set和一些通用命令「建议收藏」
Development common manual link sharing
What is SPL?
60行从零开始自己动手写FutureTask是什么体验?
Introduction to SD NAND Flash!
还在找网盘资源吗?快点收藏如下几个值得收藏的网盘资源搜索神器吧!
数分面试(一)----与业务相关
第五章:redis持久化,包括rdb和aof两种方式[通俗易懂]
three.js调试工具dat.gui使用