CF1696H.Maximum Product?

NOI/NOI+/CTSC

通过率:0%

时间限制:1.50s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a positive integer kk. For a multiset of integers SS, define f(S)f(S) as the following.

  • If the number of elements in SS is less than kk, f(S)=0f(S)=0.
  • Otherwise, define f(S)f(S) as the maximum product you can get by choosing exactly kk integers from SS.

More formally, let ∣S∣|S| denote the number of elements in SS. Then,

  • If ∣S∣<k|S| \lt k, f(S)=0f(S)=0.
  • Otherwise, f(S)=max⁡T⊆S,∣T∣=k(∏i∈Ti)f(S)=\max\limits_{T\subseteq S,|T|=k}\left(\prod\limits_{i\in T}i\right).

You are given a multiset of integers, AA. Compute ∑B⊆Af(B)\sum\limits_{B\subseteq A} f(B) modulo 109+710^9+7.

Note that in this problem, we distinguish the elements by indices instead of values. That is, a multiset consisting of nn elements always has 2n2^n distinct subsets regardless of whether some of its elements are equal.

给你一个正整数 kk。对于一个整数多重集 SS,定义函数 f(S)f(S) 如下:

  • 若 SS 中元素个数小于 kk,则 f(S)=0f(S) = 0;
  • 否则,f(S)f(S) 定义为从 SS 中恰好选出 kk 个整数所能得到的最大乘积。

更形式化地,令 ∣S∣|S| 表示 SS 中元素的个数,则:

  • 若 ∣S∣<k|S| \lt k,则 f(S)=0f(S) = 0;
  • 否则,f(S)=max⁡T⊆S, ∣T∣=k(∏i∈Ti)f(S) = \max\limits_{T\subseteq S,\,|T|=k}\left(\prod\limits_{i\in T}i\right)。

现给你一个整数多重集 AA,请计算 ∑B⊆Af(B)\sum\limits_{B\subseteq A} f(B) 对 109+710^9+7 取模的结果。

注意:本题中,我们依据下标而非数值来区分元素。即,一个包含 nn 个元素的多重集总共有 2n2^n 个互不相同的子集,无论其中是否存在相等的元素。

输入格式

The first line of input contains two integers nn and kk, where nn is the number of elements in AA (1≤k≤n≤6001\le k\le n\le 600).

The second line of input contains nn integers a1,a2,…,ana_1,a_2,\dots,a_n, describing the elements in AA (−109≤ai≤109-10^9\le a_i\le 10^9).

输入的第一行包含两个整数 nn 和 kk,其中 nn 是数组 AA 的元素个数(1≤k≤n≤6001\le k\le n\le 600)。

输入的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\dots,a_n,描述数组 AA 中的元素(−109≤ai≤109-10^9\le a_i\le 10^9)。

输出格式

Output ∑B⊆Af(B)\sum\limits_{B\subseteq A} f(B) modulo 109+710^9+7.

输出 ∑B⊆Af(B)\sum\limits_{B\subseteq A} f(B) 对 109+710^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(∅)=0f(\varnothing)=0
  • f(−1)=0f({-1})=0
  • f(2)=0f({2})=0
  • f(4)=0f({4})=0
  • f(−1,2)=−2f({-1,2})=-2
  • f(−1,4)=−4f({-1,4})=-4
  • f(2,4)=8f({2,4})=8
  • f(−1,2,4)=8f({-1,2,4})=8

So we should print (0+0+0+0−2−4+8+8) mod (109+7)=10(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 88 distinct subsets: ∅,1,1,1,1,1,1,1,1,1,1,1,1\varnothing,{1},{1},{1},{1,1},{1,1},{1,1},{1,1,1}.

考虑第一个样例。根据定义,我们知道:

  • f(∅)=0f(\varnothing)=0
  • f(−1)=0f({-1})=0
  • f(2)=0f({2})=0
  • f(4)=0f({4})=0
  • f(−1,2)=−2f({-1,2})=-2
  • f(−1,4)=−4f({-1,4})=-4
  • f(2,4)=8f({2,4})=8
  • f(−1,2,4)=8f({-1,2,4})=8

因此,我们应输出 (0+0+0+0−2−4+8+8) mod (109+7)=10(0+0+0+0-2-4+8+8)\bmod (10^9+7)=10。

在第二个样例中,注意:尽管该多重集由三个相同的值组成,它仍然具有 88 个不同的子集:∅,1,1,1,1,1,1,1,1,1,1,1,1\varnothing,{1},{1},{1},{1,1},{1,1},{1,1},{1,1,1}。

输入解题思路,AI测评打分。不知道怎么写?

首页