返回介绍

solution / 3000-3099 / 3082.Find the Sum of the Power of All Subsequences / README_EN

发布于 2024-06-17 01:02:57 字数 5268 浏览 0 评论 0 收藏 0

3082. Find the Sum of the Power of All Subsequences

中文文档

Description

You are given an integer array nums of length n and a positive integer k.

The power of an array of integers is defined as the number of subsequences with their sum equal to k.

Return _the sum of power of all subsequences of_ nums_._

Since the answer may be very large, return it modulo 109 + 7.

 

Example 1:

Input: nums = [1,2,3], k = 3

Output: 6

Explanation:

There are 5 subsequences of nums with non-zero power:

  • The subsequence [1,2,3] has 2 subsequences with sum == 3: [1,2,3] and [1,2,3].
  • The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].
  • The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].
  • The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].
  • The subsequence [1,2,3] has 1 subsequence with sum == 3: [1,2,3].

Hence the answer is 2 + 1 + 1 + 1 + 1 = 6.

Example 2:

Input: nums = [2,3,3], k = 5

Output: 4

Explanation:

There are 3 subsequences of nums with non-zero power:

  • The subsequence [2,3,3] has 2 subsequences with sum == 5: [2,3,3] and [2,3,3].
  • The subsequence [2,3,3] has 1 subsequence with sum == 5: [2,3,3].
  • The subsequence [2,3,3] has 1 subsequence with sum == 5: [2,3,3].

Hence the answer is 2 + 1 + 1 = 4.

Example 3:

Input: nums = [1,2,3], k = 7

Output: 0

Explanation: There exists no subsequence with sum 7. Hence all subsequences of nums have power = 0.

 

Constraints:

  • 1 <= n <= 100
  • 1 <= nums[i] <= 104
  • 1 <= k <= 100

Solutions

Solution 1





如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文