[ABC262D] I Hate Non-integer Number
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的更多相关文章
- java: integer number is too large
今天想定义一个类常量,结果如下面那样定义,确报错了.error is: Integer number too large public static final Long STARTTIME = 14 ...
- Fzu2109 Mountain Number 数位dp
Accept: 189 Submit: 461Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description One ...
- Codeforces 55D Beautiful Number (数位统计)
把数位dp写成记忆化搜索的形式,方法很赞,代码量少了很多. 下面为转载内容: a positive integer number is beautiful if and only if it is ...
- java 13-4 Integer和String、int之间的转换,进制转换
1.int类型和String类型的相互转换 A.int -- String 推荐用: public static String valueOf(int i) 返回 int 参数的字符串表示形式. B. ...
- 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 ...
- Codeforces 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
- fzu2109--Mountain Number(数位dp)
Problem Description One integer number x is called "Mountain Number" if: (1) x>0 and x ...
- Number Transformation
Description In this problem, you are given a pair of integers A and B. You can transform any integer ...
- hibernate NUMBER 精度
通过Hibernate映射实体时会根据数据库中NUMBER类型的精度,生成相应的POJO类中相对应的主键类型.经过亲测结果如下: NUMBER(1) POJO类中生成的是Boolean publicc ...
- 241. String to Integer
描述 Given a string, convert it to an integer. * You may assume the string is a valid integer number t ...
随机推荐
- Elasticsearch之环境搭建
一.安装 elasticsearch -- 拉取镜像 docker pull docker.elastic.co/elasticsearch/elasticsearch:8.9.1 -- 创建 doc ...
- Unity UGUI的ScrollRect(滚动视图)组件的介绍及使用
Unity UGUI的ScrollRect(滚动视图)组件的介绍及使用 1. 什么是ScrollRect组件? ScrollRect(滚动视图)是Unity UGUI中的一个常用组件,用于在UI界面中 ...
- gitlab与LDAP 联调
gitlab整理 目录 gitlab整理 1.安装Gitlab依赖包 2.下载,安装 3.配置,访问域名及邮箱 4.初始化,启动 5.访问,以及邮箱测试 5.1汉化 6.问题总结处理 6.1安装时出现 ...
- 3 分钟把高质量 AI 知识库 FastGPT 装进企业微信
FastGPT V4 已经上线,直接冲上 GitHub Trending. 如果你还不知道 FastGPT 是什么,可以先去看看作者的介绍 使用 FastGPT 构建高质量 AI 知识库 非常多的企业 ...
- 真·Redis缓存优化—97%的优化率你见过嘛?
本文通过一封618前的R2M(公司内部缓存组件,可以认为等同于Redis)告警,由浅入深的分析了该告警的直接原因与根本原因,并根据原因提出相应的解决方法,希望能够给大家在排查类似问题时提供相应的思路. ...
- 使用ensp搭建路由拓扑,并使用isis协议实现网络互通实操
转载请注明出处: 1.通过拓扑搭建如下拓扑: 其中R7.R8为L1,R6为L1/2,R9为L2. 2.配置isis实现网络互通 R7配置如下: [Huawei]isis 1 [Huawei-isis- ...
- 2023.09.29 入门级 J2 模拟赛 赛后总结(尝试第一篇总结)
T1:变换(change) 一道大水题. 赛场上想都没想就切掉了 不难发现,转换的过程只和a 和b 的二进制位有关,且不同二进制位之间无关.我们可以将a 和b 转化为二进制表示,每一位分别判断,如果这 ...
- Go 复合类型之切片类型介绍
Go 复合类型之切片类型 目录 Go 复合类型之切片类型 一.引入 二.切片(Slice)概述 2.1 基本介绍 2.2 特点 2.3 切片与数组的区别 三. 切片声明与初始化 3.1 方式一:使用切 ...
- Nuxt.js 生成sitemap站点地图文件
Nuxt.js 生成sitemap站点地图文件 背景介绍 使用nuxt框架生成静态文件支持SEO优化,打包之后需要生成一个 sitemap.xml 文件方便提交搜索引擎进行收录.官网有提供一个插件 ...
- 安装了less后仍然报错:Error: Cannot find module 'less'
结果是命令有点问题,正常来说是用下面的: npm i less –save-dev-g 然后可以正常启动了: --------------------------------------------- ...