日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

老BOJ 13 K-based Numbers

發布時間:2024/9/30 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 老BOJ 13 K-based Numbers 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
K-based Numbers
Accept:141????Submit:314
Time Limit:1000MS????Memory Limit:65536KB

Description

Let’s considerK-based numbers, containing exactlyN digits. We define a number to be valid if itsK-based notation doesn’t contain two successive zeros. For example:

  • 1010230 is a valid 7-digitnumber;

  • 1000198 is not a validnumber;

  • 0001235 is not a 7-digitnumber, it is a 4-digit number.

Given two numbersNandK,you are to calculate an amount of validK based numbers, containingN digits.

You may assume that 2 ≤K≤ 10;N≥ 2;N+K≤ 18.

Input

The numbersN andK in decimal notation separated by the line break.

Output

The result in decimal notation.

SampleInput

2

10

SampleOutput

90

1 N代表數字的位數, K代表是以什么為基的,如10進制,2進制的10和22 判斷數值是否合法:開頭不能為零, 而不能有兩個連續的0設f(n)表示符合題目條件的n位K進制的數的總數。則有:f(n)=(k-1)*(f(n-1)+f(n-2)),且f(1)=k-1,f(2)=k*(k-1)。當n==1時,直接輸出k,進行特判!

#include <stdio.h> int main(){int f[20];int n,k;scanf("%d%d",&n,&k);if(n==1) {printf("%d\n",k);return 0;}f[1]=k-1;f[2]=k*(k-1);for(int i=3; i<=n; i++)f[i]=(f[i-1]+f[i-2])*(k-1);printf("%d\n",f[n]);return 0; }

總結

以上是生活随笔為你收集整理的老BOJ 13 K-based Numbers的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。