[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 ...
随机推荐
- Qt开发思想探幽]QObject、模板继承和多继承
@ 目录 [Qt开发探幽]QObject.模板继承和多继承 1. QObject为什么不允许模板继承: 2.如果需要使用QObject进行多继承的话,子对象引用的父类链至多只能含有一个QObject ...
- MIPS寄存器堆
实验目的 熟悉并掌握 MIPS 计算机中寄存器堆的原理和设计方法 理解源操作数/目的操作数的概念 实验环境 Vivado 集成开发环境 MIPS寄存器 寄存器R0的值恒为0. 模块接口设计 1个写端口 ...
- ViTPose+:迈向通用身体姿态估计的视觉Transformer基础模型
身体姿态估计旨在识别出给定图像中人或者动物实例身体的关键点,除了典型的身体骨骼关键点,还可以包括手.脚.脸部等关键点,是计算机视觉领域的基本任务之一.目前,视觉transformer已经在识别.检测. ...
- Blazor前后端框架Known-V1.2.16
V1.2.16 Known是基于C#和Blazor开发的前后端分离快速开发框架,开箱即用,跨平台,一处代码,多处运行. Gitee: https://gitee.com/known/Known Git ...
- Codechef - Longest AND Subarray(位运算)
题目大意 给定一个正整数N,其序列为[1, 2, 3, ..., N],找到一个长度最大的连续子列,使得其所有元素取与运算的结果为正(最终输出只需要输出最大长度即可). 思路 刚开始可能并不好 ...
- stata中回归分析常用方法
// 按键盘上的PageUp可以使用上一次输入的代码(Matleb中是上箭头)// 清除所有变量clear// 清屏 和 matlab的clc类似cls // 导入数据(其实是我们直接在界面上粘贴过来 ...
- Python常用模块-20个常用模块总结
目录 time模块 datetime模块 random 模块 os 模块 sys 模块 json 和 pickle 模块 hashlib和hmac 模块 logging 模块 numpy 模块 pan ...
- 你也许不再需要使用 CSS Media Queries(媒体查询)了
你也许不再需要使用 CSS Media Queries(媒体查询)了 最近,CSS 引入了一项新功能:Container Queries.它可以替代 Media Queries 并实现 Media Q ...
- Windows虚拟机环境下Linux设置固定IP地址
Linux 设置固定IP地址 安装环境是VMware Workstation Pro 15 安装完linux之后需要做的第一件事就是配置网络,有了网络我们可以下载插件,使用xshell工具连接等等 i ...
- KubeEdge-Ianvs v0.2 发布:终身学习支持非结构化场景
本文分享自华为云社区<KubeEdge-Ianvs v0.2 发布:终身学习支持非结构化场景>,作者: 云容器大未来. 在边缘计算的浪潮中,AI是边缘云乃至分布式云中最重要的应用.随着边缘 ...