题意

给出一个长度为\(n\)的数列和数字\(X\),对于数列的每一种排列,其权值\(X\)依次对排列中的数取模,求出\(n!\)种情况最后剩下的数的权值和

分析

如果大的数字排在小的数字后面,那么大的数字对答案无影响。

可以将数列从大到小排序,然后考虑\(dp\)每个数字经过\(n\)次操作后的方案数

设\(dp[i][j]\)为\(i\)次操作后数字为\(j\)的方案数

两种转移方程

  • 选择:\(dp[i][j\mod a[i]]=dp[i][j\mod a[i]]+dp[i-1][j]\)

  • 不选:\(dp[i][j]=dp[i][j]+dp[i-1][j]*(n-i)\),不选时要将这个数放在比它小的数后面,即后面的\((n-i)\)个位置

Code

```c++
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-6;
const ll inf=1e18;
const int mod=1e9+7;
const int maxn=1e5+10;
int n,x;
int a[maxn];
ll dp[210][maxn];
int cmp(int a,int b){
return a>b;
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>x;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1,cmp);
dp[0][x]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=x;j++){
(dp[i][j%a[i]]+=dp[i-1][j])%mod;
(dp[i][j]+=dp[i-1][j]*(n-i)%mod)%mod;
}
}
ll ans=0;
for(int j=0;j<=x;j++){
ans=(ans+dp[n][j]*j%mod)%mod;
}
cout<<ans<<endl;
return 0;
}

AtCoder ExaWizards 2019 D Modulo Operations的更多相关文章

  1. AtCoder ExaWizards 2019 简要题解

    AtCoder ExaWizards 2019 简要题解 Tags:题解 link:https://atcoder.jp/contests/exawizards2019 很水的一场ARC啊,随随便便就 ...

  2. 【AtCoder】ExaWizards 2019

    ExaWizards 2019 C - Snuke the Wizard 发现符文的相对位置不变,直接二分某个位置是否到达最左或最右来计算 #include <bits/stdc++.h> ...

  3. AtCoder diverta 2019 Programming Contest 2

    AtCoder diverta 2019 Programming Contest 2 看起来我也不知道是一个啥比赛. 然后就写写题解QWQ. A - Ball Distribution 有\(n\)个 ...

  4. ExaWizards 2019 English D - Modulo Operations(DP)

    Time Limit: 2 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement Snuke has a blackb ...

  5. AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组

    题目传送门:F - Operations on a Matrix (atcoder.jp) 题意: 给一个N*M大小的零矩阵,以及Q次操作.操作1(l,r,x):对于 [l,r] 区间内的每列都加上x ...

  6. AtCoder WTF 2019 C2. Triangular Lamps Hard

    题目链接 感觉这样的题真的称得上是鬼斧神工啊,\(\text{OI}\)中能多一些这样的题目就太好了. 题意: 有一个二维的三角坐标系,大概如图所示(图是从atcoder里偷下来的): 坐标系上的每个 ...

  7. ExaWizards 2019

    AB:div 3 AB??? C:div 1 C???场内自闭的直接去看D.事实上是个傻逼题,注意到物品相对顺序不变,二分边界即可. #include<iostream> #include ...

  8. AtCoder M-SOLUTIONS 2019 Task E. Product of Arithmetic Progression

    problem link Official editorial: code: int main() { #if defined LOCAL && !defined DUIPAI ifs ...

  9. Solution -「ExaWizards 2019 C」Snuke and Wizards

    \(\mathcal{Description}\)   Link.   给定一个长度为 \(n\) 的字符串 \(s\),每个字符上初始有一张卡片.\(q\) 次操作,每次指定 \(s\) 中字符为 ...

随机推荐

  1. 关于Vue中:key="index"的console警告

    在写vue项目时,浏览器的console出现如下警告信息: [Vue warn]: Property or method "index" is not defined on the ...

  2. Flask 参数简介

    我们都知道学习了Flask的时候它里面的参数是有很多种的参数  都是需要相互进行调用传递的  今天就简要分析一些常见的参数 首先导入Flask之后看 源码 from flask import Flas ...

  3. buff/cache 内容释放

    oscache远程服务器特别卡,top命令查看获得 buff/cache 占据内存特别大,使用以下命令清理缓存: swap清理: swapoff -a && swapon -a 注意: ...

  4. 连接Mysql错误 error 1042 can't get hostname for your address

    背景: 1.etc下的hosts文件有:     127.0.0.1   localhost 2.MySQL的my.ini配置文件:     [mysqld] 节点下已经加入以下两行代码 skip-n ...

  5. python2.7与3.5共存windows平台安装

    文:铁乐与猫 2018-3-18 周日 01.首先是安装python2.7: 官网下载 https://www.python.org 点击安装包进行安装 可以选择自定义的路径 将默认打x的[add p ...

  6. zabbix 监控wind登录状态

    参考博文:http://blog.51cto.com/qicheng0211/1694583 需求:监控win 2008 的用户登录状态,无论用户登录成功与否都要告警(也可以刷选指定用户.指定时间内) ...

  7. RAC数据库的RMAN备份异机恢复到单节点数据库

    1.首先在rac环境用rman备份数据库.[oracle@rac1 admin]$ rman target /run{allocate channel c1 device type disk conn ...

  8. 关于移动端APP开发-字体样式变大问题

    前两天在写App项目的时候发现一个问题,就是明明css写的样式是14px,刚开始在页面显示时并未出现问题,可是内容一多,字体突然变大了. what?,不明所以,在各大网站上找了好久才知道是浏览器的字体 ...

  9. spring中MessageSource的配置使用方法1[转]

    本文转载仅供自己学习收录,不做任何商业用途,如有需要请访问文章原地址:http://blog.csdn.net/qyf_5445/article/details/8124306 Spring定义了访问 ...

  10. Spring-IOC MethodInvokingFactoryBean 类源码解析

    MethodInvokingFactoryBean MethodInvokingFactoryBean的作用是,通过定义类和它的方法,然后生成的bean是这个方法的返回值,即可以注入方法返回值. Me ...