UESTC 1050 Different game【思维】

186 篇文章 0 订阅

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 int
const 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);
    }
}








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值