程序员必知: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 {

相关文章
|
1天前
|
Java 程序员
程序员必知:URAL1513.LemonTale(简单的递推)
程序员必知:URAL1513.LemonTale(简单的递推)
|
10天前
|
Java
杭电acm2018 母牛的故事 Java解法 经典递归
杭电acm2018 母牛的故事 Java解法 经典递归
9 0
|
10月前
P1865 A % B Problem(欧拉筛,永远的神)
P1865 A % B Problem(欧拉筛,永远的神)
35 0
|
SQL 算法 数据挖掘
【边学边敲边记】LeetCode001:两数之和
【边学边敲边记】LeetCode001:两数之和
【边学边敲边记】LeetCode001:两数之和
|
人工智能
每天两道 CodeForces 构造/思维题 (day5)
每天两道 CodeForces 构造/思维题 (day5)
每天两道 CodeForces 构造/思维题 (day5)
|
算法
每日一题冲刺大厂第十八天 快速幂
大家好,我是泡泡,给大家带来每日一题的目的是为了更好的练习算法,我们的每日一题为了让大家练到各种各样的题目,熟悉各种题型,一年以后,蜕变成为一个不一样的自己!
65 0
|
人工智能 Java
[HDU 7136] Jumping Monkey | 并查集 | 逆向思维
Jumping Monkey Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 747 Accepted Submission(s): 360
198 0
[HDU 7136] Jumping Monkey | 并查集 | 逆向思维
|
机器学习/深度学习 物联网
[Codeforces 1586] Omkar and Determination | 思维前缀和
题意 给定一个n ∗ m 的方格,在这个方格中有一些点被标记为′ . ′ 说明这个点是没有障碍的,而′ X ′ 代表这个点是有障碍的,不能通过这个点,对于每个点,只能向上或者是向左走。如所说有的′ . ′ 点不能走出去,那么这样的′ . ′ 点就不是e x i t a b l e exitable 问题是:给定一个矩阵里面所有的 exitable点,如果给出的矩阵能够唯一确定,就是YES,否则输出 NO 所以问题就变成了给定的矩阵范围中有没有是′ . ′但是不能够 exitable的点,如果有就无法唯一确定(YES),反之就可以唯一确定(NO) 数据范围太大,可以开 vector 来模拟二维数
569 0
|
Java
HDOJ/HDU 5686 Problem B(斐波拉契+大数~)
HDOJ/HDU 5686 Problem B(斐波拉契+大数~)
87 0