题意

给出一个长度为\(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

  1. ```c++
  2. #include<bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. using namespace std;
  6. typedef long long ll;
  7. const double PI=acos(-1.0);
  8. const double eps=1e-6;
  9. const ll inf=1e18;
  10. const int mod=1e9+7;
  11. const int maxn=1e5+10;
  12. int n,x;
  13. int a[maxn];
  14. ll dp[210][maxn];
  15. int cmp(int a,int b){
  16. return a>b;
  17. }
  18. int main(){
  19. ios::sync_with_stdio(false);
  20. cin>>n>>x;
  21. for(int i=1;i<=n;i++){
  22. cin>>a[i];
  23. }
  24. sort(a+1,a+n+1,cmp);
  25. dp[0][x]=1;
  26. for(int i=1;i<=n;i++){
  27. for(int j=0;j<=x;j++){
  28. (dp[i][j%a[i]]+=dp[i-1][j])%mod;
  29. (dp[i][j]+=dp[i-1][j]*(n-i)%mod)%mod;
  30. }
  31. }
  32. ll ans=0;
  33. for(int j=0;j<=x;j++){
  34. ans=(ans+dp[n][j]*j%mod)%mod;
  35. }
  36. cout<<ans<<endl;
  37. return 0;
  38. }

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. 转: SSH框架总结(框架分析+环境搭建+实例源码下载)

    原:http://blog.csdn.net/shan9liang/article/details/8803989 首先,SSH不是一个框架,而是多个框架(struts+spring+hibernat ...

  2. swift版的CircleView

    swift版的CircleView 效果图 源码 // // CircleView.swift // CircleView // // Created by YouXianMing on 15/10/ ...

  3. [翻译] JTSReachability

    JTSReachabilit An adaptation of Apple's Reachability with some block-based conveniences. 这是一个苹果的网络检测 ...

  4. DoraHacks的笔记

    DoraHacks的笔记

  5. 12-5 张雨RTCM3数据解码解不出的原因

    数据大小:75kB 时间12-4 原因:二进制数据乱码,未通过电文头检验 2018-12-10 08:44:05 张雨RTCM32-MSM4无法固定,连差分都没有

  6. python处理数据(二)

    处理PDF文件 PyPDF2简介 作为 PDF 工具包构建的纯 python 库. 它可以:提取文档信息(标题,作者,... ...)一页一页地分割文件一页一页地合并文件裁剪页面将多个页面合并成一个页 ...

  7. 4-3 R语言函数 mapply

    #mapply(函数/函数名,数据,函数相关的函数) > list(rep(1,4),rep(2,3),rep(3,2),rep(4,1)) [[1]] [1] 1 1 1 1 [[2]] [1 ...

  8. 如何使用正则做文本数据的清洗(附免费AI视频福利)

    手工打造文本数据清洗工具 作者 白宁超 2019年4月30日09:43:59 前言:数据清理指删除.更正错误.不完整.格式有误或多余的数据.数据清理不仅仅更正错误,同样加强来自各个单独信息系统不同数据 ...

  9. 1898: [Zjoi2005]Swamp 沼泽鳄鱼

    1898: [Zjoi2005]Swamp 沼泽鳄鱼 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1582 Solved: 870 [Submit][S ...

  10. _viewstart.cshtml的作用

    在ASP.NET MVC 3.0及更高版本中,用Razor模板引擎新建项目后,Views目录下会出现一个这样的文件:_ViewStart.cshtml. _viewstart.cshtml的作用 1. ...