UESTC 1050 Different game【思维】

来源:互联网 发布:淘宝怎么游戏交易 编辑:程序博客网 时间:2024/06/05 06:11

Different game

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)

Submit Status

Alice is playing a new game recently. In this game, there are nn different kinds of cards. We assume that Alice have cici pieces of cards for ithith kind.

Alice is asked to divide them into mm piles and then arrange each pile in one line. After that, Alice will get mm sequences. For convenience, the sequences are labeled S1,S2,⋯,SmS1,S2,⋯,SmFor each i<ji<j , Alice will get some points, equal to the length of the LCS(longest common subsequence) of SiSi and SjSj. The total points is the sum of points for all i<ji<j.

Now Alice is wondering the maximum points she can get.

As is known to everyone of you, Bob loves Alice very much. Could you tell Bob the answer to help Bob leave a good impression on Alice.

Input

The first line contains 22 integers mm and nn, indicating the number of sequences and the number of different kinds of card.

The second line contains nn integers cici, indicating the number of ithith card.

It is guaranteed that 1≤n,m≤100000,0≤ci≤1000001≤n,m≤100000,0≤ci≤100000.

Output

Print the answer module 1000000007 in one line.

Sample input and output

Sample Input

Sample Output

2 2

2 3

2

 

题目大意:


有N个数字,要求你分成m个序列,每个数字的量已知 。

求ΣLCS(i,j);


思路:


我们均分每个数字即可。


Ans=Σci/m*C(m,2)+m-(ci/m)*C(m-(ci/m),2);


Ac代码:

#include<stdio.h>#include<string.h>using namespace std;#define ll long long intconst ll mod=1e9+7;ll C(ll x){    return x*(x-1)*500000004;}int main(){    ll n,m;    while(~scanf("%lld%lld",&n,&m))    {        ll output=0;ll x;        for(ll i=1;i<=n;i++)        {            scanf("%lld",&x);            output+=x/m*C(m) + C(x-x/m*m);            output%=mod;        }        printf("%lld\n",output);    }}








原创粉丝点击