A15258 | Maximum Product?
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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)=\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.
- 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)=\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.
输入格式
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$ ).
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 $\sum\limits_{B\subseteq A} f(B)$ modulo $10^9+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(\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\}$ .
- $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\}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted