题意

给出一个长度为\(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. Dos命令删除添加新服务

    安装服务sc create Svnservice binpath= "d:\subversion\bin\svnserve.exe --service -r E:\projectversio ...

  2. Memorize and recite an important historical speech

    Memorize and recite an important historical speech memorize['memәraiz]v.[亦作memorise] 记住, 记忆 historic ...

  3. UI(二)之正式过程

    2018-12-04 09:48:25 1.SetWindowsHookEx ·钩子实际上是一个处理消息的程序段,通过系统调用,把它挂入系统.每当特定的消息发出,在没有到达目的窗口前,钩子程序就先捕获 ...

  4. c++作业之圆面积

    代码传送门

  5. Mysql数据库字符集问题

    修改mysql数据库的默认编码方式 修改my.ini文件 加上 default-character-set=gb2312 设定数据库字符集 alter database da_name default ...

  6. 【问题定位】tcpdump 抓包简易命令

    tcpdump -A -i lo port 2003 or port 2103 or port 2203 | grep '.*system.*'

  7. 【node.js】函数、路由

    Node.js中函数的使用与Javascript类似,一个函数可以作为另一个函数的参数.我们可以先定义一个函数,然后传递,也可以在传递参数的地方直接定义函数. function say(word) { ...

  8. criterions的选择

    criterions分为几类,其中有classification criterions与regression criterions.classification criterions是针对离散的,re ...

  9. 【PHP函数】json_decode() ---- 对 JSON 格式的字符串进行解码

    json_decode() --- 对 JSON 格式的字符串进行解码 1.用法: mixed json_decode ( string $json [, bool $assoc = false [, ...

  10. python+requests实现接口测试 - cookies的使用

    在很多时候,发送请求后,服务端会对发送请求方进行身份识别,如果请求中缺少识别信息或存在错误的识别信息, 会造成识别失败. 如一些需要用户登录以后才能访问的页面. import requests mya ...