Problem Statement

You are given a sequence of positive integers $A=(a_1,\ldots,a_N)$ of length $N$.

There are $(2^N-1)$ ways to choose one or more terms of $A$. How many of them have an integer-valued average? Find the count modulo $998244353$.

Constraints

  • $1 \leq N \leq 100$
  • $1 \leq a_i \leq 10^9$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$a_1$ $\ldots$ $a_N$

Output

Print the answer.


Sample Input 1

3
2 6 2

Sample Output 1

6

For each way to choose terms of $A$, the average is obtained as follows:

  • If just $a_1$ is chosen, the average is $\frac{a_1}{1}=\frac{2}{1} = 2$, which is an integer.

  • If just $a_2$ is chosen, the average is $\frac{a_2}{1}=\frac{6}{1} = 6$, which is an integer.

  • If just $a_3$ is chosen, the average is $\frac{a_3}{1}=\frac{2}{1} = 2$, which is an integer.

  • If $a_1$ and $a_2$ are chosen, the average is $\frac{a_1+a_2}{2}=\frac{2+6}{2} = 4$, which is an integer.

  • If $a_1$ and $a_3$ are chosen, the average is $\frac{a_1+a_3}{2}=\frac{2+2}{2} = 2$, which is an integer.

  • If $a_2$ and $a_3$ are chosen, the average is $\frac{a_2+a_3}{2}=\frac{6+2}{2} = 4$, which is an integer.

  • If $a_1$, $a_2$, and $a_3$ are chosen, the average is $\frac{a_1+a_2+a_3}{3}=\frac{2+6+2}{3} = \frac{10}{3}$, which is not an integer.

Therefore, $6$ ways satisfy the condition.


Sample Input 2

5
5 5 5 5 5

首先枚举选了 $i$ 个数,那么这 $i$ 个数的和一定是 $i$ 的倍数。所以在模 $i$ 的意义下dp。统计 a 中有多少个数模 $i$ 余 $j$,枚举使用了那些余数,设 $dp_{j,k,l}$ 表示用了前 $j$ 个余数,目前的所有和模 $i$ 余 $k$,选了 $l$ 个数。则枚举余数为 $j$ 选多少个,然后转移就行了。

#include<bits/stdc++.h>
const int N=105,P=998244353;
int n,a[N],c[N],dp[N][N][N],ans,f[N][N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",a+i);
f[0][0]=1;
for(int i=1;i<=n;i++)
{
f[i][0]=f[i][i]=1;
for(int j=1;j<i;j++)
f[i][j]=(f[i-1][j]+f[i-1][j-1])%P;
}
for(int i=1;i<=n;i++)
{
memset(c,0,sizeof(c));
for(int j=1;j<=n;j++)
c[a[j]%i]++;
memset(dp,0,sizeof(dp));
dp[0][0][0]=1;
for(int j=0;j<i;j++)//枚举用到那个余数
{
for(int k=0;k<=c[j];k++)//用几个
{
for(int y=0;y<i;y++)
{
for(int w=k;w<=i;w++)
{
dp[j+1][y][w]+=1LL*dp[j][(y-k*j%i+i)%i][w-k]*f[c[j]][k]%P,dp[j+1][y][w]%=P;
}
}
}
}
ans+=dp[i][0][i],ans%=P;
// printf("%d\n",dp[1][0][2]);
}
printf("%d",ans);
}

[ABC262D] I Hate Non-integer Number的更多相关文章

  1. java: integer number is too large

    今天想定义一个类常量,结果如下面那样定义,确报错了.error is: Integer number too large public static final Long STARTTIME = 14 ...

  2. Fzu2109 Mountain Number 数位dp

    Accept: 189    Submit: 461Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description One ...

  3. Codeforces 55D Beautiful Number (数位统计)

    把数位dp写成记忆化搜索的形式,方法很赞,代码量少了很多. 下面为转载内容:  a positive integer number is beautiful if and only if it is  ...

  4. java 13-4 Integer和String、int之间的转换,进制转换

    1.int类型和String类型的相互转换 A.int -- String 推荐用: public static String valueOf(int i) 返回 int 参数的字符串表示形式. B. ...

  5. Codeforces Beta Round #51 B. Smallest number dfs

    B. Smallest number Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/pro ...

  6. Codeforces 55D Beautiful Number

    Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...

  7. fzu2109--Mountain Number(数位dp)

     Problem Description One integer number x is called "Mountain Number" if: (1) x>0 and x ...

  8. Number Transformation

    Description In this problem, you are given a pair of integers A and B. You can transform any integer ...

  9. hibernate NUMBER 精度

    通过Hibernate映射实体时会根据数据库中NUMBER类型的精度,生成相应的POJO类中相对应的主键类型.经过亲测结果如下: NUMBER(1) POJO类中生成的是Boolean publicc ...

  10. 241. String to Integer

    描述 Given a string, convert it to an integer. * You may assume the string is a valid integer number t ...

随机推荐

  1. paging组件的用法和意义

    一.Paging组件的意义 分页加载是在应用程序开发过程中十分常见的需求,我们经常需要以列表的方式加载大量的数据,这些数据通常来自网络或本地数据库.然而,如果一次性将所有数据全部加载出来,必然会消耗大 ...

  2. 支持JDK19虚拟线程的web框架,之三:观察运行中的虚拟线程

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本篇是<支持JDK19虚拟线程的web ...

  3. 【matplotlib基础】--样式表

    Matplotlib库 由于诞生的比较早,所以其默认的显示样式很难符合现在的审美,这也是它经常为人诟病的地方. 不过,经过版本更迭之后,现在 Matplotlib 已经内置了很多样式表,通过使用不同的 ...

  4. 理解并掌握C#的Channel:从使用案例到源码解读(一)

    引言 在C#的并发编程中,Channel是一种非常强大的数据结构,用于在生产者和消费者之间进行通信.本文将首先通过一个实际的使用案例,介绍如何在C#中使用Channel,然后深入到Channel的源码 ...

  5. pandas(进阶操作)-- 处理非数值型数据 -- 数据分析三剑客(核心)

    博客地址:https://www.cnblogs.com/zylyehuo/ 开发环境 anaconda 集成环境:集成好了数据分析和机器学习中所需要的全部环境 安装目录不可以有中文和特殊符号 jup ...

  6. torch.nn.ReLU(inplace=True)的具体含义:

    首先根据源文档中的ReLU(x)=max(0,x),得出结论.大于0的数值不变,小于0的数据变成0. 补充:这里需要注意的是 ReLU并没有限制数据的大小. 这是对应的文档链接:https://pyt ...

  7. 入门篇-其之六-Java运算符(中)

    祝所有程序员,1024节日快乐!!! 一.自增/自减运算符 假设有一个变量intValue的值为10,如果想让这个值加1,有哪些方式? 首先,我们可以使用最原始的方式: int intValue = ...

  8. 虹科案例|Redis企业版数据库:金融行业客户案例解读

    传统银行无法提供无缝的全渠道客户体验.无法实时检测欺诈.无法获得业务洞察力.用户体验感较差.品牌声誉受损和业务损失?虹科提供的Redis企业版数据库具有低延迟.高吞吐和可用性性能,实施Redis企业版 ...

  9. Centos7安装Promethus

    安装Prometheus(普罗米修斯)监控: 实验环境准备: 服务器 IP地址 Prometheus服务器 192.168.1.22 被监控服务器 192.168.1.20 grafana服务器 19 ...

  10. Python 利用pandas和matplotlib绘制饼图

    这段代码使用了Pandas和Matplotlib库来绘制店铺销售数量占比的饼图.通过读取Excel文件中的数据,对店铺名称进行聚合并按销售数量降序排列,然后使用Matplotlib绘制饼图展示销售数量 ...