Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 600600 points

Problem Statement

Snuke has a blackboard and a set SS consisting of NN integers. The ii-th element in SS is SiSi.

He wrote an integer XX on the blackboard, then performed the following operation NN times:

  • Choose one element from SS and remove it.
  • Let xx be the number written on the blackboard now, and yy be the integer removed from SS. Replace the number on the blackboard with xmodyxmody.

There are N!N! possible orders in which the elements are removed from SS. For each of them, find the number that would be written on the blackboard after the NN operations, and compute the sum of all those N!N! numbers modulo 109+7109+7.

Constraints

  • All values in input are integers.
  • 1≤N≤2001≤N≤200
  • 1≤Si,X≤1051≤Si,X≤105
  • SiSi are pairwise distinct.

Input

Input is given from Standard Input in the following format:

NN XX
S1S1 S2S2 …… SNSN

Output

Print the answer.


Sample Input 1 Copy

Copy
2 19
3 7

Sample Output 1 Copy

Copy
3
  • There are two possible orders in which we remove the numbers from SS.
  • If we remove 33 and 77 in this order, the number on the blackboard changes as follows: 19→1→119→1→1.
  • If we remove 77 and 33 in this order, the number on the blackboard changes as follows: 19→5→219→5→2.
  • The output should be the sum of these: 33.

Sample Input 2 Copy

Copy
5 82
22 11 6 5 13

Sample Output 2 Copy

Copy
288

Sample Input 3 Copy

Copy
10 100000
50000 50001 50002 50003 50004 50005 50006 50007 50008 50009

Sample Output 3 Copy

Copy
279669259
  • Be sure to compute the sum modulo 109+7109+7.

题意:

给定一个数x和一个含有n个数的数组。

将数组排成任意顺序(即一共有N!种顺序组合),然后扫一遍数组,x对a[i] 取模,余数代替x,然后对下一个数进行同样的操作。

直到扫完整个数组。最后得到的数是num

然后把所有顺序组合得到的num全加起来就是ans,需要对1e9+7取模。

思路:

通过分析我们可以知道,

当数组的一个数a[i]前面有一个数a[x],并且a[x] 比 a[i] 小。那么我们分析上面的取余操作可以知道a[i]其实对答案没有任何影响。

因为在对a[i]取余之前的数值x,已经比a[i]小了,因为对a[x]取余过了,一个小数对大数取余,没有改变的。

那么我们对数组从大到小排序后,

定义dp[i][j] 表示,排列了前i个数后,当前值x为j的所有情况数。

转移有两种,

如果a[i] 数放在 i位置,

那么我们知道他对i位置 j%a[ i ] 的贡献是上一个位置i-1的j的数量。

如果a[i] 不放在这个位置。

它放在后面的n-i的任意位置都可以,而且对当前位置i的j即dp[i][j]的贡献就是dp[i-1][j] ,因为这一位的 a[i] 没有影响。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int a[maxn];
int n;
int x;
ll dp[][];
const ll mod=1e9+;
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
gbtb;
cin>>n>>x;
repd(i,,n)
{
cin>>a[i];
}
sort(a+,a++n,[&](int x,int y){return x>y;});
dp[][x]=;
repd(i,,n)
{
repd(j,,x)
{
dp[i][j%a[i]]+=dp[i-][j];
dp[i][j%a[i]]=(dp[i][j%a[i]]+mod)%mod;
dp[i][j]+=dp[i-][j]*(n-i)%mod;
dp[i][j]=(dp[i][j]+mod)%mod;
}
}
ll ans=0ll;
repd(i,,x)
{
ans+=(dp[n][i]*i)%mod;
ans=(ans+mod)%mod;
}
cout<<ans<<endl; return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

ExaWizards 2019 English D - Modulo Operations(DP)的更多相关文章

  1. jzoj6009. 【THUWC2019模拟2019.1.18】Counting (dp)

    Description 羽月最近发现,她发动能力的过程是这样的: 构建一个 V 个点的有向图 G,初始为没有任何边,接下来羽月在脑中构建出一个长度为 E 的边的序列,序列中元素两两不同,然后羽月将这些 ...

  2. 2019湘潭校赛 H(dp)

    题目传送 dp是常规的:\(m^2\)的预处理:把位置存进vector然后\(O(1)\)算出想要的:WA点:要注意特意设置一下val[i][v.size()]=0,即全天都放鸽子则花费时间为0. # ...

  3. [贪心,dp] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 Fishing Master (Problem - 6709)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6709 Fishing Master Time Limit: 2000/1000 MS (Java/Othe ...

  4. HDU 5938 Four Operations(四则运算)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  5. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  6. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  7. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  8. GAITC 2019全球人工智能技术大会(南京)

    2019年5月25日至26日,由中国人工智能学会主办,以“交叉.融合.相生.共赢”为主题的2019GAITC将在南京全新亮相. 2019 全球人工智能技术大会(2019 GAITC)以“前端引领.深度 ...

  9. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

随机推荐

  1. javascript sort 函数用法

    sort 函数 博客地址:https://ainyi.com/41 简单的说,sort() 在没有参数时,返回的结果是按升序来排列的.即字符串的Unicode码位点(code point)排序 [5, ...

  2. 【.NET Core项目实战-统一认证平台】第七章 网关篇-自定义客户端限流

    [.NET Core项目实战-统一认证平台]开篇及目录索引 上篇文章我介绍了如何在网关上增加自定义客户端授权功能,从设计到编码实现,一步一步详细讲解,相信大家也掌握了自定义中间件的开发技巧了,本篇我们 ...

  3. 如何将html特殊字符编码转换成特殊字符_html十进制编码字符转回来

    备注:有时候我们会莫名其妙遇到一些特殊字符:  这些字符在网页上能正常显示,但是在APP特殊情景并不识别这些字符: 如:'     这个其实是单引号:   '     百度后发现,它其实是HTML特殊 ...

  4. [转]Centos 7搭建Gitlab服务器超详细

    本文转自:https://blog.csdn.net/duyusean/article/details/80011540 可参考:https://about.gitlab.com/install/#c ...

  5. 数据结构(java版)学习笔记(二)——线性表之顺序表

    顺序表的优点: 随机存取元素方便,根据定位公式容易确定表中每个元素的存储位置,所以要指定第i个结点很方便 简单,直观 顺序表的缺点: 插入和删除结点困难 扩展不灵活,难以确定分配的空间 容易造成浪费 ...

  6. Java 学习笔记 IO流与File操作

    可能你只想简单的使用,暂时不想了解太多的知识,那么请看这里,了解一下如何读文件,写文件 读文件示例代码 File file = new File("D:\\test\\t.txt" ...

  7. JavaScript是如何工作的:使用MutationObserver跟踪DOM的变化

    摘要: 掌握MutationObserver. 这是专门探索 JavaScript 及其所构建的组件的系列文章的第10篇. 如果你错过了前面的章节,可以在这里找到它们: JavaScript 是如何工 ...

  8. SDOI 2018划水记

    Day0 最后一天啦,此时不颓更待何时? 上午10:15坐车从gryz出发,在一路颓废中到了农大 不得不说,农大的宾馆真的好高档啊,壁橱里面居然有保险柜!电视柜厨子里居然有冰箱!!冰箱里居然有饮料!! ...

  9. Dynamics 365执行操作报SQL Server已超时,更改这个超时设置的方法

    本人微信公众号:微软动态CRM专家罗勇 ,回复291或者20190110可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 当执 ...

  10. Android 图片加载框架 Glide4.x

    概述 Glide是一个图片加载框架,使得我们可以轻松的加载和展示图片 Glide4.x新增apply()来进行设置,apply可以调用多次,但是如果两次apply存在冲突的设置,会以最后一次为准 新增 ...