编程介的小学生 2019-08-26 21:56 采纳率: 20.5%
浏览 226

DP的一个计算 用C语言

Problem Description

Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0,1,2,…and the column from left to right 0,1,2,….If using C(n,k) represents the number of row n, column k. The Yang Hui Triangle has a regular pattern as follows.
C(n,0)=C(n,n)=1 (n ≥ 0)
C(n,k)=C(n-1,k-1)+C(n-1,k) (0<k<n)
Write a program that calculates the minimum sum of numbers passed on a route that starts at the top and ends at row n, column k. Each step can go either straight down or diagonally down to the right like figure 2.
As the answer may be very large, you only need to output the answer mod p which is a prime.

Input
Input to the problem will consists of series of up to 100000 data sets. For each data there is a line contains three integers n, k(0<=k<=n<10^9) p(p<10^4 and p is a prime) . Input is terminated by end-of-file.

Output
For every test case, you should output "Case #C: " first, where C indicates the case number and starts at 1.Then output the minimum sum mod p.

Sample Input
1 1 2
4 2 7

Sample Output
Case #1: 0
Case #2: 5

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何实现从tello无人机上获取视频流,然后将获取的视频通过yolov5进行检测
    • ¥15 WPF使用Canvas绘制矢量图问题
    • ¥15 用三极管设计一个单管共射放大电路
    • ¥15 孟德尔随机化r语言运行问题
    • ¥15 pyinstaller编译的时候出现No module named 'imp'
    • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
    • ¥15 怎么把多于硬盘空间放到根目录下
    • ¥15 Matlab问题解答有两个问题
    • ¥15 LCD12864中文显示
    • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决