B题
多重序列
https://ac.nowcoder.com/acm/problem/204779
思路:
因为每个数都是k的正整数次幂,所以可以直接以正整数次幂的形式存起来,是k的几次幂就存几,然后
根据,求最大的指数和,最后求就行了.
Code:
#include <iostream> #include <cstdio> #include <map> #define ll long long using namespace std; const int N = 2020; map<ll, ll> sq; ll n, m, k, a[N][N], mod, ans; ll qpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } int main() { scanf("%lld%lld%lld%lld", &n, &m, &k, &mod); if (k == 1) { cout << 1 % mod; return 0; } else { int i = 0; ll cnt = 1; while (cnt < 10000000000010) { sq[cnt] = i; ++ i; cnt *= k; } } for (int i = 1; i <= n; ++ i) { ll cnt = 0; for (int j = 1; j <= m; ++ j) { scanf("%lld", &a[i][j]); cnt += sq[a[i][j]]; } ans = max(ans, cnt); } cout << qpow(k, ans); return 0; }