当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2158:A Difficult Mathematics Problem

题目描述
Here is a difficult mathematics problem; your job is to solve it.

Given two integer N and K, we have
A(N, K) = {a | a = (a1 a2 a3 … aN), ai is integer and 0 <= ai <= K-1, i = 1,...,N}.

We define a function d = Image(a) from A(N, K) to A(N-1, K) as below:
For any a = (a1 a2 a3 ... aN), which is belonged to A(N, K), we have d = (d1 d2 ... dN-1) = Image(a) with di = min(ai, ai+1), i.e., di is the smaller one between ai and ai+1.

You should calculate the expression below

For any element a belonged to A(N, K), the expression first obtains d = (d1 d2 ... dN-1) = Image(a); then gain a value by calculating (d1+1)(d2+1)...(dN-1+1). Each a corresponding to a value, and f(N, K) is just the sum of these values.

For example, If N = 2, K = 3, then A(N, K)={(00), (01), (02), (11), (10), (12), (20), (21), (22)}; the values obtained from each element in A(N, K) are 1, 1, 1, 2, 1, 2, 1, 2, 3 and we can know that f(2, 3) = 14 by adding these values.
输入解释
The input consists of only one line, which contains two integer N and K (N = 2, 3, 4. And if N=2, we has 1 <= K <= 5000; if N=3, we has 1 <= K <= 1000; if N=4, we has 1 <= K <= 500).
输出解释
The output contains a single integer, which is the value of f(N, K). It's confirmed that the result is less than 2^63.
输入样例
2 3
输出样例
14

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 POJ Monthly,李学武

源链接: POJ-2158

最后修改于 2020-10-29T06:25:05+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000 65536