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. Linux校验文件MD5和SHA值的方法

    1.需求背景 下载或传输文件后,需要计算文件的MD5.SHA256等校验值,以确保下载或传输后的文件和源文件一致 2.校验方法 如上图所示,可以使用Linux自带的校验命令来计算一个文件的校验值 Li ...

  2. 通过Nginx权限认证拦截资源

    nginx认证转发模块 Module ngx_http_auth_request_module   详细参考官网 ngx_http_auth_request_module (nginx.org) 模块 ...

  3. Go 并发编程 - 并发安全(二)

    什么是并发安全 并发情况下,多个线程或协程会同时操作同一个资源,例如变量.数据结构.文件等.如果不保证并发安全,就可能导致数据竞争.脏读.脏写.死锁.活锁.饥饿等一系列并发问题,产生重大的安全隐患,比 ...

  4. 使用 Laf 一周内上线美术狮 AI 绘画小程序

    "美术狮 AI 绘画"(以下简称"美术狮"),是我们小团队的一次尝试,定位是人人都可以上手的,充满创意的,理解中文和中国文化的图片生成工具. 在完善图像模型和论 ...

  5. 探索API接口:从概念到实践

    在当今数字化时代,API(Application Programming Interface)接口成为了各种应用程序之间实现数据交互和功能集成的关键.无论是开发一个网站.构建一个移动应用还是进行数据分 ...

  6. openNebula集群搭建

    openNebula集群搭建 目录 openNebula集群搭建 OpenNebula概述 环境介绍及部署前准备 1. 安装步骤 1.关闭防火墙 2.配置epel源地和opennebula源 3.安装 ...

  7. vscod 配置 morkdown 快捷键

    vscod 配置 morkdown 快捷键 1.首先在根目录添加.vscode 文件夹 ️1.1 新建一个 settings.json 文件 { "[markdown]": { & ...

  8. KRPano插件解密大师更新支持最新版KRPano的XML/JS解密

    KRPano插件解密大师是一款专业的全景解密工具,它可以帮助你轻松解密KRPano的XML/JS插件,还能分析下载静态和动态网站的资源.你无需任何编程知识,只需一键点击,就能快速完成解密,学习全景开发 ...

  9. KRPano多屏互动原理

    KRPano可以实现多个屏幕之间的同步显示,主要应用到Websocket技术进行通信. 在控制端,我们需要发送当前KRPano场景的实时的视角和场景信息,可以使用如下的代码: embedpano({ ...

  10. 基于百度AI实现文字和图像敏感内容审核

    前言 百度AI是指百度公司的人工智能技术全称.它采用深度学习技术,包括自然语言处理.语音识别.计算机视觉.知识图谱等,可应用于各个领域如互联网.医疗.金融.教育.汽车.物流等.百度AI的发展将帮助人类 ...