AtCoder ExaWizards 2019 D Modulo Operations
题意
给出一个长度为\(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的更多相关文章
- AtCoder ExaWizards 2019 简要题解
AtCoder ExaWizards 2019 简要题解 Tags:题解 link:https://atcoder.jp/contests/exawizards2019 很水的一场ARC啊,随随便便就 ...
- 【AtCoder】ExaWizards 2019
ExaWizards 2019 C - Snuke the Wizard 发现符文的相对位置不变,直接二分某个位置是否到达最左或最右来计算 #include <bits/stdc++.h> ...
- AtCoder diverta 2019 Programming Contest 2
AtCoder diverta 2019 Programming Contest 2 看起来我也不知道是一个啥比赛. 然后就写写题解QWQ. A - Ball Distribution 有\(n\)个 ...
- ExaWizards 2019 English D - Modulo Operations(DP)
Time Limit: 2 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement Snuke has a blackb ...
- 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 ...
- AtCoder WTF 2019 C2. Triangular Lamps Hard
题目链接 感觉这样的题真的称得上是鬼斧神工啊,\(\text{OI}\)中能多一些这样的题目就太好了. 题意: 有一个二维的三角坐标系,大概如图所示(图是从atcoder里偷下来的): 坐标系上的每个 ...
- ExaWizards 2019
AB:div 3 AB??? C:div 1 C???场内自闭的直接去看D.事实上是个傻逼题,注意到物品相对顺序不变,二分边界即可. #include<iostream> #include ...
- AtCoder M-SOLUTIONS 2019 Task E. Product of Arithmetic Progression
problem link Official editorial: code: int main() { #if defined LOCAL && !defined DUIPAI ifs ...
- Solution -「ExaWizards 2019 C」Snuke and Wizards
\(\mathcal{Description}\) Link. 给定一个长度为 \(n\) 的字符串 \(s\),每个字符上初始有一张卡片.\(q\) 次操作,每次指定 \(s\) 中字符为 ...
随机推荐
- [swift] Async
Async https://github.com/duemunk/Async Syntactic sugar in Swift for asynchronous dispatches in Grand ...
- Python学习---JSON补充内容[中文编码 + dumps解析]
JSON补充内容[微信解决中文乱码,接上] import json # 英文显示 dic = {"hello": "world"} str = json.dum ...
- 铁乐学python_day28_模块学习3
大部份内容摘自授课老师的博客http://www.cnblogs.com/Eva-J/ OS模块复习一二 >>> import os >>> os.getcwd() ...
- eclipse缓慢了么?
我的eclipse突然变得无比缓慢,javaw.exe的cpu使用率高达85%! 可是我什么也没做啊.项目组的其他同事询问过后,也没有谁修改了eclipse的配置文件(.setting文件夹 .cl ...
- November 19th 2016 Week 47th Saturday
Nature didn't need an operation to be beautiful. It just was. 自然之美无需刻意而为,其本身即为美. Recently I saw seve ...
- Basestation函数解析(一)
---恢复内容开始--- 1._tmain _tmain()是微软操作系统(windows)提供的对unicode字符集和ANSI字符集进行自动转换用的程序入口点函数. 首先,这个_tmain() ...
- springboot 配置jpa启动报Error processing condition on org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration.pageableCustomizer
springboot +gradle 配置jpa启动报Error processing condition on org.springframework.boot.autoconfigure.data ...
- 超简单,centos7安装docker
1.在centos7上直接yum安装docker [root@localhost ~]# yum install docker 2.启动docker [root@localhost ~]#servic ...
- Java实现Package编译和访问
Java实现Package编译和访问 说明 所有文件都是使用UTF-8编码来写的,请不要用Windows记事本随便打开 Test.java文件中注释的方法说明了该类是不能访问其方法的 文件目录树 bi ...
- [转]打造自己的LINQ Provider(上):Expression Tree揭秘
概述 在.NET Framework 3.5中提供了LINQ 支持后,LINQ就以其强大而优雅的编程方式赢得了开发人员的喜爱,而各种LINQ Provider更是满天飞,如LINQ to NHiber ...