跳到正文

题解

P8557 题解

zhang_kevin约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
P8557

版本

  1. v1当前

这道题需要用到排列组合的知识,不会的建议去看我的博客。

我们可以先从这 nn 种金属入手。

对于任意一种金属,它可以被任意 1∼k1 \sim k 个熔炉所造出来,方案总数为:

Ck1+Ck2+Ck3+⋯⋯+Ckk−1+Ckk=2k−1C^1_k+C^2_k+C^3_k+\cdots\cdots+C^{k-1}_k+C^k_k = 2^k-1

现在有 nn 种金属,每一种金属有 2k−12^k-1 种方法,总方案数为 (2k−1)n(2^k-1)^n,配上快速幂模板即可。

C++
#include<bits/stdc++.h>
#define int unsigned long long
#define endl '\n'
using namespace std;
const int mod = 998244353;

int ksm(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1)
			ans = ans * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return ans;
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, k, ans = 0;
	cin >> n >> k;
	cout << ksm(ksm(2, k)-1, n) << endl;
	return 0;
}
原文