URAL 1513. Lemon Tale(简单的递推)
2017-05-30 11:16
483 查看
写几组数据就会发现规律了啊。
。但是我是竖着看的。。
。还找了半天啊、、、
只是要用高精度来写,水题啊。就当熟悉一下java了啊。
num[i] = 2*num[i-1]-num[i-2-k]。
Time limit: 1.0 second
Memory limit: 64 MB
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.
As a result a word "lemon" was mentioned N times in the statement.
Besides, the problem 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?
"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".
。但是我是竖着看的。。
。还找了半天啊、、、
只是要用高精度来写,水题啊。就当熟悉一下java了啊。
num[i] = 2*num[i-1]-num[i-2-k]。
1513. Lemon Tale
Time limit: 1.0 secondMemory limit: 64 MB
Background
For each programmer a point comes when the last contest is lost, and it is time to retire. Even Three Programmers themselves could not escape the common lot. But the Programmers also wanted to keepa 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 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 ≤ 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 { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n, k; BigInteger num[] = new BigInteger [100005]; while(cin.hasNext()) { n = cin.nextInt(); k = cin.nextInt(); BigInteger ans; BigInteger p = BigInteger.valueOf(2); ans = p.pow(n); if(k == 0) { System.out.println(1); continue; } if(n == k) { System.out.println(ans); continue; } num[0] = BigInteger.valueOf(1); for(int i = 1; i <= k+1; i++) { num[i] = p.pow(i-1); } for(int i = k+2; i <= n; i++) { num[i] = num[i-1].multiply(BigInteger.valueOf(2)); num[i] = num[i].subtract(num[i-2-k]); } ans = BigInteger.valueOf(0); for(int i = n; i >= (n-k); i--) { ans = ans.add(num[i]); } System.out.println(ans); } } }
相关文章推荐
- URAL 1513. Lemon Tale(简单的递推)
- 【URAL 1513】Lemon Tale(DP+高精度)
- URAL 1260 Nudnik Photographer 简单的递推
- URAL 1009. K-based Numbers(简单递推)
- URAL 1225(Flags)简单递推
- poj2680 Computer Transformation----简单的递推
- URAL 1577. E-mail(简单二维dp)
- UVA 550 Multiplying by Rotation (简单递推)
- URAL 1018 Binary Apple Tree 简单树形背包
- 近期简单题目小结 UVA 100+HDU 2007+URAL 1084+Poj 1152+UVA 10042+UVA 11752+UVA 10780
- hdu 4472 Count(简单递推)
- Timus Online Judge1009---K-based Numbers(简单递推dp)
- URAL 1020 Rope 简单几何
- URAL 1108 简单的树形dp背包问题
- 2050折线分割平面(简单递推)(折线切分平面)
- POJ 2441 Arrange the Bulls 状态压缩递推简单题 (状态压缩DP)
- 递推关系的运用加简单DP【UVA11137Ingenuous Cubrency】-------2015年1月27日
- URAL 1309 Dispute <函数关系的递推>
- HDU 2042 不容易系列之二【简单递推】
- hdu 5366 简单递推