码迷,mamicode.com
首页 > 其他好文 > 详细

UESTC 1050 Different game 构造法

时间:2016-04-01 18:43:07      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

Different game

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

Alice is playing a new game recently. In this game, there are n different kinds of cards. We assume that Alice have ci pieces of cards for ith 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<j, Alice will get some points, equal to the length of 

the LCS(longest common subsequence) of Si and Sj. The total points is the sum of points for all i<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 2 integers m and n, indicating the number of sequences and the number of different kinds of card.

The second line contains n integers ci, indicating the number of ith card.

It is guaranteed that 1n,m100000,0ci100000     .

Output

Print the answer module 1000000007 in one line.

Sample input and output

Sample Input Sample Output
2 2
2 3
2

Source

The 13th UESTC Programming Contest Final

My Solution

把第 i 种card的ci张卡先 ci/m分配给m个piles,多余的 ci % m 丢到最后,然后用 n*(n-1)/2  和 m*(m-1)/2 每次输入ci的时候计算并取模就好;
大致像这样构造
1 1 1 1 2 2 3 3 3 3 3 3 1 2 3
1 1 1 1 2 2 3 3 3 3 3 3 1 2 3
1 1 1 1 2 2 3 3 3 3 3 3 1 2 
1 1 1 1 2 2 3 3 3 3 3 3    2 
1 1 1 1 2 2 3 3 3 3 3 3    2 
1 1 1 1 2 2 3 3 3 3 3 3       

#include <iostream>
#include <cstdio>
using namespace std;
const int HASH = 1000000007;
int main()
{
    int m, n, c;
    long long ans = 0;
    scanf("%d%d", &m, &n);
    for(int i = 1; i <= n; i++){
        scanf("%d", &c);
        ans = (ans + (c/m)*(m*(m-1)/2) + (c%m)*(c%m-1)/2) % HASH;
    }
    printf("%lld", ans);
    return 0;
}

Thank you!

UESTC 1050 Different game 构造法

标签:

原文地址:http://blog.csdn.net/prolightsfxjh/article/details/51029788

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!