题意

给出一个长度为\(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. 设计带有placeHolder的TextView

    设计带有placeHolder的TextView 效果: 源码: PlaceholderTextView.h 与 PlaceholderTextView.m // // PlaceholderText ...

  2. 使用Charles进行网络请求抓包解析

    使用Charles进行网络请求抓包解析 0. 懒人的福音(⌐■_■)(破解版下载地址,记得安装java库支持) http://pan.baidu.com/s/1c08ksMW 1. 查看电脑的ip地址 ...

  3. Forefront TMG 之 ISP 冗余传输链路(ISP-R)

    在 Forefront TMG 中,新增了ISP 冗余传输链路功能:在 TMG 中,你可以同时使用两条活动的外部链路,使用模式分为以下两种: 故障转移模式:在主要链路工作正常的情况下,所有的流量都通过 ...

  4. Python学习---装饰器/迭代器/生成器的学习【all】

    Python学习---装饰器的学习1210 Python学习---生成器的学习1210 Python学习---迭代器学习1210

  5. Linux ifconfig命令详解

    ifconfig(interfaces config).通常需要以root身份登录或使用sudo来使用ifconfig工具 ifconfig 命令用来查看和配置网络设备.当网络环境发生改变时可通过此命 ...

  6. Linux alias命令详解

    alias:内置命令(没有路径),设置命令的别名,保护系统,方便 unalias:别名取消 常用的命令展示 临时设置 alias cp='cp –i' unalias cp      取消系统的别命令 ...

  7. oracle 启动报错ORA-27125解决方案

    脚本: oracle@edwdb:~> id uid=(oracle) gid=(oinstall) (oinstall),(dba) oracle@edwdb:~> su - root ...

  8. 关于Matlab里面的四个取整(舍入)函数:Floor, Ceil, Fix, Round的解释(转)

    转自http://blog.sina.com.cn/s/blog_48ebd4fb010009c2.html   floor:朝负无穷方向舍入 B = floor(A) rounds the elem ...

  9. 团队开发中,eclipse中安装jre

    团队合作中配置jre时,jre名称应该保持一致,否则不要提交.classpath文件 window-preferences     团队合作中,JRE name一定要一致!

  10. (1)I/O流 (2)线程

    1.I/O流1.1 ObjectOutputStream类(重点)(1)基本概念 java.io.ObjectOutputStream类主要用于将Java对象整体写入到输出流中. 只能将支持 java ...