当前位置:网站首页>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;
}
边栏推荐
- 第四章:activiti流程中,变量的传递和获取流程变量 ,设置和获取多个流程变量,设置和获取局部流程变量「建议收藏」
- 第五章:activiti流程分流判断,判断走不同的任务节点
- GCC编译的时候头文件搜索规则
- JS introduction to reverse the recycling business network of learning, simple encryption mobile phone number
- The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
- Getting started with Polkadot parachain development, this article is enough
- static linking and dynamic linking
- 创建一个 Dapp,为什么要选择波卡?
- Opencv图像缩放和平移
- 一个栈的输入序列为1 2 3 4 5 的出站顺序的理解
猜你喜欢
Introduction to SD NAND Flash!
语音社交软件开发——充分发挥其价值
什么是 DevOps?看这一篇就够了!
产品太多了,如何实现一次登录多产品互通?
The host computer develops C# language: simulates the STC serial port assistant to receive the data sent by the microcontroller
高质量 DeFi 应用构建指南,助力开发者玩转 DeFi Summer
Voice-based social software development - making the most of its value
Jenkins manual (2) - software configuration
【 temperature warning program DE development 】 event driven model instance
[Strong Net Cup 2022] WP-UM
随机推荐
Huawei's lightweight neural network architecture GhostNet has been upgraded again, and G-GhostNet (IJCV22) has shown its talents on the GPU
Chapter 5: Multithreaded Communication—wait and notify
LeetCode 216. Combined Sum III (2022.08.04)
单片机:温度控制DS18B20
2022 Hangzhou Electric Power Multi-School Session 6 1008.Shinobu Loves Segment Tree Regular Questions
【MindSpore易点通机器人-01】你也许见过很多知识问答机器人,但这个有点不一样
Voice-based social software development - making the most of its value
高质量 DeFi 应用构建指南,助力开发者玩转 DeFi Summer
创建一个 Dapp,为什么要选择波卡?
Complete image segmentation efficiently based on MindSpore and realize Dice!
第五章:多线程通信—wait和notify
我们的Web3创业项目,黄了
Still looking for a network backup resources?Hurry up to collect the following network backup resource search artifact it is worth collecting!
Opencv算术操作
Chapter 4: activiti RuntimeService settings get and get process variables, and the difference from taskService, set process variables when starting and completing tasks [easy to understand]
three objects are arranged in a spherical shape around the circumference
RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
电竞、便捷、高效、安全,盘点OriginOS功能的关键词
【温度预警程序de开发】事件驱动模型实例运用
一文道清什么是SPL