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. 每日一库:fsnotify简介

    fsnotify是一个用Go编写的文件系统通知库.它提供了一种观察文件系统变化的机制,例如文件的创建.修改.删除.重命名和权限修改.它使用特定平台的事件通知API,例如Linux上的inotify,m ...

  2. .NET6.0实现IOC容器

    .NET6.0实现IOC容器 IOC的作用这里省略-只对如何使用进行说明. 1. 创建一个.NET6应用程序 这里使用 .NET6.0 WebAPI 应用 2. 声明接口 public interfa ...

  3. 在线问诊 Python、FastAPI、Neo4j — 创建药品节点

    目录 前提条件 创建节点 Demo 准备数据 创建药品标签节点 在线问诊 Python.FastAPI.Neo4j - 创建节点 Neo4j 节点的标签可以理解为 Java 中的实体. 根据常规流程: ...

  4. 基于 ActionFilters 的限流库DotNetRateLimiter使用

    前言 在构建API项目时,有时出于安全考虑,防止访问用户恶意攻击,希望限制此用户ip地址的请求次数,减轻拒绝服务攻击可能性,也称作限流.接下来,我们就来学习开源库DotNetRateLimiter 如 ...

  5. 加密 K8s Secrets 的几种方案

    前言 你可能已经听过很多遍这个不算秘密的秘密了--Kubernetes Secrets 不是加密的!Secret 的值是存储在 etcd 中的 base64 encoded(编码) 字符串.这意味着, ...

  6. Solution -「洛谷 P4688」「YunoOI 2016」掉进兔子洞

    Description (Link)[https://www.luogu.com.cn/problem/P4688]. 每次询问三个区间,把三个区间中同时出现的数一个一个删掉,问最后三个区间剩下的数的 ...

  7. oracle问题:ORA-09817及解决办法

    某天以管理员身份登录公司测试库报ORA-09817错误,查了网上的文章说是审计文件没有存储空间造成的.我的这问题也证实了这一点,现将解决步骤分享: 1.发现问题:报ORA-09817 oracle@l ...

  8. Django-rest-framework框架——Web应用模式、API接口、接口测试工具(Postman)、RESTfulAPI规范、序列化、drf、环境安装与配置、CBV源码分析、 APIView

    @ 目录 一 Web应用模式 1.1 前后端不分离 1.2 前后端分离 二 API接口 三 接口测试工具:Postman 四 RESTful API规范(背诵牢记) 4.1 数据的安全保障 4.2 接 ...

  9. 中华人民共和国企业所得税月(季)度预缴纳税申报表(A类,2018年版)

    企业按照<中华人民共和国公司法>有关规定整体改制,包括非公司制企业改制为有限责任公司或股份有限公司,有限责任公司变更为股份有限公司,股份有限公司变更为有限责任公司,原企业投资主体存续并在改 ...

  10. Go 复合类型之切片类型介绍

    Go 复合类型之切片类型 目录 Go 复合类型之切片类型 一.引入 二.切片(Slice)概述 2.1 基本介绍 2.2 特点 2.3 切片与数组的区别 三. 切片声明与初始化 3.1 方式一:使用切 ...