当前位置:网站首页>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;
}
边栏推荐
- The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
- 这份阿里强推的并发编程知识点笔记,将是你拿大厂offer的突破口
- 技术干货 | 基于 MindSpore 实现图像分割之豪斯多夫距离
- uniapp 连接ibeacon
- 数据中台建设(十):数据安全管理
- How can project cost control help project success?
- The query that the user's test score is greater than the average score of a single subject
- [Strong Net Cup 2022] WP-UM
- FPGA:开发环境Vivado的使用
- 第九章:activit内置用户组设计与组任务分配和IdentityService接口的使用
猜你喜欢
华为轻量级神经网络架构GhostNet再升级,GPU上大显身手的G-GhostNet(IJCV22)
告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来
数据中台建设(十):数据安全管理
The century-old Nordic luxury home appliance brand ASKO smart wine cabinet in the three-temperature area presents the Chinese Valentine’s Day, and tastes the love of the delicacy
RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
【 temperature warning program DE development 】 event driven model instance
Ali's new launch: Microservices Assault Manual, all operations are written out in PDF
012_SSS_ Improving Diffusion Model Efficiency Through Patching
还在找网盘资源吗?快点收藏如下几个值得收藏的网盘资源搜索神器吧!
随机推荐
PCB布局必知必会:教你正确地布设运算放大器的电路板
[Android] How to use RecycleView in Kotlin project
【综合类型第 35 篇】程序员的七夕浪漫时刻
First Decentralized Heist?Loss of nearly 200 million US dollars: analysis of the attack on the cross-chain bridge Nomad
2022杭电多校 第6场 1008.Shinobu Loves Segment Tree 规律题
Introduction to SD NAND Flash!
百年北欧奢华家电品牌ASKO智能三温区酒柜臻献七夕,共品珍馐爱意
GPU-CUDA-图形渲染分析
机器学习-基础知识 - Precision, Recall, Sensitivity, Specificity, Accuracy, FNR, FPR, TPR, TNR, F1 Score, Bal
【MindSpore Easy-Diantong Robot-01】You may have seen many knowledge quiz robots, but this one is a bit different
Chapter 5: Activiti process shunting judgment, judging to go to different task nodes
How can project cost control help project success?
反射修改jsessionid实现Session共享
Create a Dapp, why choose Polkadot?
Brief Analysis of WSGI Protocol
入门 Polkadot 平行链开发,看这一篇就够了
Data Middle Office Construction (10): Data Security Management
如何修改管理工具client_encoding
poj2287 Tian Ji -- The Horse Racing(2016xynu暑期集训检测 -----C题)
第六章:activiti流程分流判断之排它网关和并行网关