CF1696H.Maximum Product?
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a positive integer k . For a multiset of integers S , define f(S) as the following.
- If the number of elements in S is less than k , f(S)=0 .
- Otherwise, define f(S) as the maximum product you can get by choosing exactly k integers from S .
More formally, let ∣S∣ denote the number of elements in S . Then,
- If ∣S∣<k , f(S)=0 .
- Otherwise, f(S)=T⊆S,∣T∣=kmax(i∈T∏i) .
You are given a multiset of integers, A . Compute B⊆A∑f(B) modulo 109+7 .
Note that in this problem, we distinguish the elements by indices instead of values. That is, a multiset consisting of n elements always has 2n distinct subsets regardless of whether some of its elements are equal.
输入格式
The first line of input contains two integers n and k , where n is the number of elements in A ( 1≤k≤n≤600 ).
The second line of input contains n integers a1,a2,…,an , describing the elements in A ( −109≤ai≤109 ).
输出格式
Output B⊆A∑f(B) modulo 109+7 .
输入输出样例
输入#1
3 2 -1 2 4
输出#1
10
输入#2
3 1 1 1 1
输出#2
7
输入#3
10 4 -24 -41 9 -154 -56 14 18 53 -7 120
输出#3
225905161
输入#4
15 5 0 0 2 -2 2 -2 3 -3 -3 4 5 -4 -4 4 5
输出#4
18119684
说明/提示
Consider the first sample. From the definitions we know that
- f(∅)=0
- f({−1})=0
- f({2})=0
- f({4})=0
- f({−1,2})=−2
- f({−1,4})=−4
- f({2,4})=8
- f({−1,2,4})=8
So we should print (0+0+0+0−2−4+8+8)mod(109+7)=10 .
In the second example, note that although the multiset consists of three same values, it still has 8 distinct subsets: ∅,{1},{1},{1},{1,1},{1,1},{1,1},{1,1,1} .