Codeforces Global Round 21
H
Maximum Product?
Codeforces
3500
原题
← G→
翻译中…

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| \lt k$, $f(S)=0$.
  • Otherwise, $f(S)=\max\limits_{T\subseteq S,|T|=k}\left(\prod\limits_{i\in T}i\right)$.
翻译中…

You are given a multiset of integers, $A$. Compute $\sum\limits_{B\subseteq A} f(B)$ modulo $10^9+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 $2^n$ distinct subsets regardless of whether some of its elements are equal.

翻译中…

Input

翻译中…

The first line of input contains two integers $n$ and $k$, where $n$ is the number of elements in $A$ ($1\le k\le n\le 600$).

翻译中…

The second line of input contains $n$ integers $a_1,a_2,\dots,a_n$, describing the elements in $A$ ($-10^9\le a_i\le 10^9$).

翻译中…

Output

翻译中…

Output $\sum\limits_{B\subseteq A} f(B)$ modulo $10^9+7$.

翻译中…

Note

翻译中…

Consider the first sample. From the definitions we know that

翻译中…
  • $f(\varnothing)=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)\bmod (10^9+7)=10$.

翻译中…

In the second example, note that although the multiset consists of three same values, it still has $8$ distinct subsets: $\varnothing,\{1\},\{1\},\{1\},\{1,1\},\{1,1\},\{1,1\},\{1,1,1\}$.

翻译中…

样例

Input #1
3 2
-1 2 4
Output #1
10
InputCopy OutputCopy
Input #2
3 1
1 1 1
Output #2
7
InputCopy OutputCopy
Input #3
10 4
-24 -41 9 -154 -56 14 18 53 -7 120
Output #3
225905161
InputCopy OutputCopy
Input #4
15 5
0 0 2 -2 2 -2 3 -3 -3 4 5 -4 -4 4 5
Output #4
18119684
InputCopy OutputCopy
题目信息
题号
1696H
时间限制
1.5 s
内存限制
512 MB
标签
暴力
组合数学
动态规划
贪心
模拟
数学
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。