luogu#P8560. 约定(Promise)

    ID: 7320 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学洛谷原创O2优化组合数学生成函数快速傅里叶变换 FFT拉格朗日反演

约定(Promise)

Background

In a city turned into ruins, heavy rain poured down.

After “Walpurgis Night” was defeated, Madoka and Homura were also covered in wounds and collapsed because they had run out of magic power.

“We... are finished too...” Madoka sighed softly.

“What about the Grief Seed?” Homura’s voice still carried a bit of hope.

Madoka said nothing. She looked up at the sky and could only shake her head helplessly.

“I see... Then, I mean, let’s just become witches together and mess everything in this world up.” As Homura spoke, she could not help but sob. “Destroy all those hateful things and sad things, as if they never happened. Destroy, destroy, destroy it all... Don’t you think that’s fine too?”

With a crisp clink, Homura felt magic power flow into her Soul Gem. She turned her head and saw Madoka smiling, holding a Grief Seed.

“That was a lie just now,” Madoka’s smile was still as sweet as ever. “I kept one.”

Homura hurriedly hugged Madoka’s arm and asked, “Why, why are you giving it to me?”

“Because there is something I can’t do, but you can, Homura-chan. I want to ask you...” Madoka said. “Homura-chan, you can go back to the past, right? You said you rewrote history to avoid an ending like this...”

“Yeah...”

Madoka finally could not hold back her sadness either, and clear tears slid down her face. “Can you go and save that stupid me, the one who hasn’t been tricked by Kyubey yet?”

“I promise you, I will definitely save you! No matter how many times it takes, I will protect you!”

“That’s great...” Madoka calmed down, but in the next moment, black mist spread out from her Soul Gem, and her expression twisted in pain. “Can I... ask you one more thing?”

Homura nodded gently.

“I... don’t want to become a witch...” Madoka’s voice grew even weaker. “Even if there are hateful things and sad things, there are still many things I want to protect in this world.” Madoka struggled to raise her arm, supporting the pitch-black Soul Gem in her hand.

“Madoka...” Homura pulled out her pistol and aimed at Madoka’s Soul Gem. Amid Homura’s painful crying, she pulled the trigger.

Problem Description

Mio was watching Puella Magi Madoka Magica with Rin for the NN-th time. When they reached one of the most tear-jerking scenes in the whole show, their parents suddenly pushed the door open. Mio did not want to be caught slacking off, so she quickly switched the window and pretended they were doing a counting problem:

Define the weight of a labeled, rooted, left-right-unordered binary tree as: the sum of the weights of the subtrees rooted at “all children of the root node”, plus dd. In particular, define the weight of a tree with only one node as 11. Compute the sum of the kk-th powers of the weights over all such trees with nn nodes. Output the answer modulo 998244353998244353.

“Isn’t this that problem from NaCly_Fish's Math Contest ...?” Rin looked at the statement and whispered, “So boring. I’m not reading this problem.”

Input Format

One line with three positive integers n,k,dn,k,d.

Output Format

One line with one integer, the answer.

3 0 2
9
3 2 2
198
4 3 2
16008
6 4 2
58351320
514 250 114
354914151

Hint

[Sample 11 Explanation]

There are 99 labeled rooted binary trees with 33 nodes, as shown below. The red node indicates the root.
Since k=0k=0, the sum of the kk-th powers of all tree weights equals the total number of trees, so the answer is 99.

[Sample 22 Explanation]
Continuing from the figure above: the weights of the trees in the first row are all 55, and the weights of the trees in the second row are 44, so the answer is 6×52+3×42=1986\times 5^2+3\times 4^2=198.

[Constraints]

This problem uses bundled testdata.

Subtask 1 (5 pts): n6n \le 6.
Subtask 2 (9 pts): k=0k=0, n107n\le 10^7.
Subtask 3 (14 pts): n105n\le 10^5.
Subtask 4 (18 pts): k4000k \le 4000, n107n\le 10^7.
Subtask 5 (23 pts): k105k \le 10^5.
Subtask 6 (31 pts): no special constraints.

For 100%100\% of the data, 2n,d9×1082\le n,d \le 9\times 10^8, 0k5×1060\le k \le 5\times 10^6.

Translated by ChatGPT 5