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

相关文章
|
7月前
【洛谷 P1219】[USACO1.5]八皇后 Checker Challenge 题解(深度优先搜索+回溯法)
**USACO1.5八皇后挑战**是关于在$n\times n$棋盘上放置棋子的,确保每行、每列及两条主对角线上各有一个且仅有一个棋子。给定$6$作为输入,输出前$3$个解及解的总数。例如,对于$6\times6$棋盘,正确输出应包括解的序列和总数。代码使用DFS解决,通过跟踪对角线占用状态避免冲突。当找到所有解时,显示前三个并计数。样例输入$6$产生输出为解的前三个排列和总数$4$。
52 0
|
7月前
|
Java 程序员
程序员必知:URAL1513.LemonTale(简单的递推)
程序员必知:URAL1513.LemonTale(简单的递推)
38 0
HJ76--尼科彻斯定理
HJ76--尼科彻斯定理
125 0
ACM刷题之路(二十一)大素数筛选 2019暑期集训 POJ 2689 Prime Distance
ACM刷题之路(二十一)大素数筛选 2019暑期集训 POJ 2689 Prime Distance
ACM刷题之路(二十四)HDU 2844 多重背包转换 Coins
ACM刷题之路(二十四)HDU 2844 多重背包转换 Coins
113 0
ACM刷题之路(十五) 分治法 + 找规律 ZOJ4085
ACM刷题之路(十五) 分治法 + 找规律 ZOJ4085
115 0
ACM刷题之路(十九)二分+尺取 2019暑期集训 HDU6231 K-th Number
ACM刷题之路(十九)二分+尺取 2019暑期集训 HDU6231 K-th Number
|
C语言
C语言程序设计第五版 谭浩强 P137 3,6,8,9题解
C语言程序设计第五版 谭浩强 P137 3,6,8,9题解
103 0
|
C语言
C语言程序设计第五版 谭浩强p 215-216 1. 4. 6. 8.11题解
C语言程序设计第五版 谭浩强p 215-216 1. 4. 6. 8.11题解
205 0
|
C语言
C语言程序设计第五版 谭浩强 P107 3,4,6,8,9题解
1)3+4>5 优先3+4得到结果7,因此7>5结果为真; 4==5为假,一真一假逻辑与最终结果为假。结果为0 (2)优先算术运算4+5得到7,非0则为真,4-5得到-1,非0则为真,||和&&优先级最低,自左向右运算,3||7结果为1,1&&-1结果为1,一真一假逻辑与最终结果为假。结果为1
123 0