编程介的小学生 2017-01-18 15:38 采纳率: 20.5%
浏览 727
已采纳

A Difficult Mathematics Problem

Description

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.
Input

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).
Output

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.
Sample Input

2 3
Sample Output

14

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-01-24 15:46
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码