CF514E.Darth Vader and Tree

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

When Darth Vader gets bored, he sits down on the sofa, closes his eyes and thinks of an infinite rooted tree where each node has exactly n sons, at that for each node, the distance between it an its i-th left child equals to d__i. The Sith Lord loves counting the number of nodes in the tree that are at a distance at most x from the root. The distance is the sum of the lengths of edges on the path between nodes.

But he has got used to this activity and even grew bored of it. 'Why does he do that, then?' — you may ask. It's just that he feels superior knowing that only he can solve this problem.

Do you want to challenge Darth Vader himself? Count the required number of nodes. As the answer can be rather large, find it modulo 109 + 7.

当达斯·维达感到无聊时,他会坐在沙发上,闭上眼睛,想象一棵无限的有根树,其中每个节点恰好有 nn 个子节点;并且对每个节点而言,它到其第 ii 个左子节点的距离等于 did_i。这位西斯领主热衷于计算树中与根节点距离不超过 xx 的节点数量。此处的距离定义为连接两节点的路径上所有边的长度之和。

但他已对此活动习以为常,甚至感到厌倦。“那他为何还要这么做呢?”——你或许会问。其实,仅仅是因为他自认为高人一等,知道唯有自己能解决这个问题。

你是否想向达斯·维达本人发起挑战?请计算满足条件的节点数量。由于答案可能非常大,请对 109+710^9 + 7 取模。

输入格式

The first line contains two space-separated integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 109) — the number of children of each node and the distance from the root within the range of which you need to count the nodes.

The next line contains n space-separated integers d__i (1 ≤ d__i ≤ 100) — the length of the edge that connects each node with its i-th child.

第一行包含两个以空格分隔的整数 nn 和 xx(1 ≤ n ≤ 1051 ≤ n ≤ 10^5,0 ≤ x ≤ 1090 ≤ x ≤ 10^9)—— 分别表示每个节点的子节点数量,以及需要统计节点数的距离范围(即从根节点出发的距离不超过 xx)。

第二行包含 nn 个以空格分隔的整数 did_i(1 ≤ di ≤ 1001 ≤ d_i ≤ 100)—— 表示连接每个节点与其第 ii 个子节点的边的长度。

输出格式

Print a single number — the number of vertexes in the tree at distance from the root equal to at most x.

输出一个整数——树中到根节点的距离不超过 xx 的顶点个数。

输入输出样例

  • 输入#1

    3 3
    1 2 3

    输出#1

    8

说明/提示

Pictures to the sample (the yellow color marks the nodes the distance to which is at most three)

示例图(黄色标记的节点表示其到指定节点的距离不超过三)

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

首页