程序员必知:URAL1513.LemonTale(简单的递推)

简介: 程序员必知:URAL1513.LemonTale(简单的递推)

写几组数据就会发现规律了啊。

。但是我是竖着看的。。

。还找了半天啊、、、

只是要用高精度来写,水题啊。就当熟悉一下java了啊。

num【i】 = 2*num【i-1】-num【i-2-k】。

1513. Lemon Tale

Time limit: 1.0 second

Memory limit: 64 MB

Background

For each programmer a point comes when the last contest //代码效果参考:http://www.ezhiqi.com/zx/art_2184.html is lost, and it is time to retire. Even Three Programmers themselves could not escape the common lot. But the Programmers also wanted to keep

a good memory about themselves. For this noble purpose they created problems and organized extremely popular programming contests from time to time. Of course, this work was not well paid, but for true programmers a glory was more important than money.

However it is only the first half of a job to think out a brilliant problem. The second one is to create a politically correct statement for it.

Problem

The matter is the statement of some problem for the upcoming contest was written by the Third Programmer, who knew nothing about political correctness. He just wrote a story about citrus plants growing.

As a result a word "lemon" was mentioned N times in the statement.

Besides, the problem //代码效果参考:http://www.ezhiqi.com/zx/art_3694.html is to be looked through by famous censor Alexander K. right before the contest. And it is a known fact, that lemons remind him of oranges he hates furiously. It worries the First

and the Second Programmers greatly - they know exactly, that if a word "lemon" occurs more than Ktimes successively, the problem will be immediately disqualified from the contest.

That is why the First and the Second Programmers connived secretly to login to the server at the eve of the contest and replace some "lemons" with much more politically correct "bananas" so that the

problem could not be disqualified. How many ways are there to do it?

Input

The only line contains the integer numbers N (1 ≤ N ≤ 10000) and K (0 //代码效果参考:http://www.ezhiqi.com/bx/art_2227.html ≤ K ≤ N).

Output

You should output the desired number of ways.

Sample

input

output

5 2

24

Hint

Let us denote a word "lemon" by a letter "L" and a word "banana" by a letter "B". So in the sample the initial sequence of words "LLLLL" might be transformed into the following politically correct sequences:

"LLBLL", "LLBLB", "LLBBL", "LLBBB", "LBLLB", "LBLBL", "LBLBB", "LBBLL", "LBBLB", "LBBBL", "LBBBB", "BLLBL", "BLLBB", "BLBLL", "BLBLB", "BLBBL", "BLBBB", "BBLLB", "BBLBL", "BBLBB", "BBBLL", "BBBLB", "BBBBL" and "BBBBB".

import java.math.BigInteger;

import java.util.Scanner;

public class Main {

相关文章
|
存储 NoSQL Redis
Redis的Lua脚本有什么作用?
Redis Lua脚本用于减少网络开销、实现原子操作及扩展指令集。它能合并操作降低网络延迟,保证原子性,替代不支持回滚的事务。通过脚本,代码复用率提高,且可自定义指令,如实现分布式锁,增强Redis功能和灵活性。
572 1
|
Windows
已解决Win11报错 OSError: [WinError 1455] 页面文件太小,无法完成操作。
Win11报错 OSError: [WinError 1455] 页面文件太小,无法完成操作。 Error loading "D:\aaaa\envs\gs\lib\site-packages\torch\lib\caffe2_detectron_ops_gpu.dll" or one of its dependencies.
12163 0
已解决Win11报错 OSError: [WinError 1455] 页面文件太小,无法完成操作。
|
监控 安全 Shell
【Shell 命令集合 系统管理 】Linux 查看系统上的失败登录记录 lastb命令 使用指南
【Shell 命令集合 系统管理 】Linux 查看系统上的失败登录记录 lastb命令 使用指南
622 0
|
开发工具 Android开发
Android AppsFlyer接入及测试
SDK接入 AppsFlyer:Android-SDK集成 SDK与Android平台的兼容性 1、Android 4.0以上 2、非移动Android平台,例如智能电视,包括亚马逊的Fire TV 3、Android应用程式的店外市场,例如Amazon和Baidu
3569 0
Android AppsFlyer接入及测试
|
7月前
|
运维 Linux 开发者
Linux系统中使用Python的ping3库进行网络连通性测试
以上步骤展示了如何利用 Python 的 `ping3` 库来检测网络连通性,并且提供了基本错误处理方法以确保程序能够优雅地处理各种意外情形。通过简洁明快、易读易懂、实操性强等特点使得该方法非常适合开发者或系统管理员快速集成至自动化工具链之内进行日常运维任务之需求满足。
457 18
|
前端开发 JavaScript Android开发
Flutter 与 React Native - 详细深入对比分析(2024 年)
Flutter和React Native是两大跨平台框架,各有优缺点。Flutter性能优越,UI灵活,使用Dart;React Native生态广泛,适合JavaScript开发。
3946 6
Flutter 与 React Native - 详细深入对比分析(2024 年)
|
存储 C语言
【C语言】输入/输出函数详解
在C语言中,输入/输出操作是通过标准库函数来实现的。这些函数分为两类:标准输入输出函数和文件输入输出函数。
1529 6
|
存储 人工智能 数据可视化
阿里云服务器的十二种典型应用场景
阿里云还提供了数据可视化服务DataV,帮助用户通过图形化的界面轻松搭建专业水准的可视化应用。用户可以利用DataV进行数据监控、调度和会展演示等工作,提高数据分析和决策的效率。
|
Linux Android开发 iOS开发
FFmpeg开发笔记(七)欧拉系统编译安装FFmpeg
FFmpeg跨平台支持多系统,包括Linux、macOS、Windows和Android。官方提供[编译指南](https://trac.ffmpeg.org/wiki/CompilationGuide)。在CentOS上,编译涉及安装多个依赖,如NASM、Yasm、libx264、libx265、libfdk_aac等。同样,在EulerOS上,需安装相关工具并分别编译x264、x265和FFmpeg。详细FFmpeg开发内容可参考《FFmpeg开发实战:从零基础到短视频上线》。
627 1
FFmpeg开发笔记(七)欧拉系统编译安装FFmpeg
|
SQL 监控 安全
网络攻击的阶段详解
【8月更文挑战第31天】
965 0