Secret of Chocolate Poles

Time Limit : 1 sec, Memory Limit : 262144 KB

Problem A Secret of Chocolate Poles

Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are 1 cm thick, and the thick disks are k cm thick. Disks will be piled in glass cylinders.

Each pole should satisfy the following conditions for her secret mission, which we cannot tell.

  • A pole should consist of at least one disk.
  • The total thickness of disks in a pole should be less than or equal to l cm.
  • The top disk and the bottom disk of a pole should be dark.
  • A disk directly upon a white disk should be dark and vice versa.

As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when l=5 and k=3.

Figure A.1. Six chocolate poles corresponding to Sample Input 1

Your task is to count the number of distinct side views she can make for given l and k to help her accomplish her secret mission.

Input

The input consists of a single test case in the following format.

l k

Here, the maximum possible total thickness of disks in a pole is l cm, and the thickness of the thick disks is k cm. l and k are integers satisfying 1≤l≤100 and 2≤k≤10.

Output

Output the number of possible distinct patterns.

Sample Input 1

5 3

Sample Output 1

6

Sample Input 2

9 10

Sample Output 2

5

Sample Input 3

10 10

Sample Output 3

6

Sample Input 4

20 5

Sample Output 4

86

Sample Input 5

100 2

Sample Output 5

3626169232670

Source: ACM International Collegiate Programming Contest , Asia Regional Tsukuba, Tsukuba, Japan, 2017-12-17 
http://icpc.iisf.or.jp/2017-tsukuba/

题意:有三种盘子,1 cm厚的黑盘,1 cm厚的白盘,和 k cm厚的黑盘,最上面和最下面一定是黑盘,同颜色的盘子不能相邻,总厚度在 l cm 以内有多少种放法;

以黑盘个数做标记,忽略厚度不同,共有 (l+1)/ 2 种方法,每种再用厚盘替换普通黑盘,可以替换 1~ i 个,写个组合数就行了;

#include <iostream>
#include <cstring>
#include<cstdio>
using namespace std;
long long int c(long long m,long long n)
{
long long ans=1;
for(long long k=1; k<=n; k++)
{
ans=(ans*(m-n+k))/k;
}
return ans;
}
int main()
{
long long l, k;
while(cin >> l >> k)
{
long long i, j;
long long sum = 0;
for( i=1; i<=(l+1)/2; i++)
{
sum++;
for( j=1; j<=i; j++ )
{
if( i-j+k*j + i-1 > l) break;
sum += c(i,j);
}
}
printf("%lld\n",sum);
}
return 0;
}

Aizu-1378- ICPC Asia 2017-Secret of Chocolate Poles的更多相关文章

  1. Secret of Chocolate Poles (Aizu1378——dp)

    Select Of Chocolate Poles 题意:有一个竖直放置的高度为l cm的盒子,现在有三种方块分别为1cm的白块,1cm的黑块,k cm的黑块,要求第一块放进去的必须是黑色的,盒子最上 ...

  2. Aizu - 1378 Secret of Chocolate Poles (DP)

    你有三种盘子,黑薄,白薄,黑厚. 薄的盘子占1,厚的盘子占k. 有一个高度为L的桶,盘子总高度不能超出桶的总高度(可以小于等于).相同颜色的盘子不能挨着放. 问桶内装盘子的方案数. 如 L = 5,k ...

  3. 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  4. 2017 ACM ICPC Asia Regional - Daejeon

    2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...

  5. 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest

    2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...

  6. 2017 ACM/ICPC Asia Regional Qingdao Online

    Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submi ...

  7. ICPC Asia Nanning 2017 I. Rake It In (DFS+贪心 或 对抗搜索+Alpha-Beta剪枝)

    题目链接:Rake It In 比赛链接:ICPC Asia Nanning 2017 Description The designers have come up with a new simple ...

  8. ICPC Asia Nanning 2017 L. Twice Equation (规律 高精度运算)

    题目链接:Twice Equation 比赛链接:ICPC Asia Nanning 2017 Description For given \(L\), find the smallest \(n\) ...

  9. ICPC Asia Nanning 2017 F. The Chosen One (高精度运算)

    题目链接:The Chosen One 比赛链接:ICPC Asia Nanning 2017 题意 \(t\) 组样例,每组给出一个整数 \(n(2\le n\le 10^{50})\),求不大于 ...

随机推荐

  1. 关于iOS URL缓存机制原理解析

    关于URL缓存机制中   利用request对象判断是否缓存   其实request是否相等的判断依据是URLString是否相等

  2. 657. Judge Route Circle机器人能否返回

    [抄题]: Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this r ...

  3. 十万个为什么:现在还没发现“虚函数virtual”和多态性的优点,估计是因为我还没有编程序吧。

    十万个为什么:现在还没发现“虚函数virtual”和多态性的优点,估计是因为我还没有编程序吧.

  4. p1429 平面最近点对(加强版)

    传送门 分析 我们可以枚举每一个点算它的最近点 估价函数应该分为3种情况计算: 大于max,小于min,位于min和max之间 代码 #include<iostream> #include ...

  5. Luogu 2000 拯救世界

    从胡小兔的博客那里过来的,简单记一下生成函数. 生成函数 数列$\{1, 1, 1, 1, \cdots\}$的生成函数是$f(x) = 1 + x + x^2 + x^3 + \cdots$,根据等 ...

  6. tornado异步请求非阻塞-乾颐堂

    前言 也许有同学很迷惑:tornado不是标榜异步非阻塞解决10K问题的嘛?但是我却发现不是torando不好,而是你用错了.比如最近发现一个事情:某网站打开页面很慢,服务器cpu/内存都正常.网络状 ...

  7. osg反走样

    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; traits-& ...

  8. Linux内核版本

    在Linux中找到/usr/src/kernels/目录,该目录下面有一个系统内核文件 例如:2.6.32-431.11.2.el6.x86_64 Linux内核版本规则 Linux内核版本有三组数字 ...

  9. 那些原生的javascript APIs

    在前端开发的时候,我们往往会使用javascript 框架,使用框架的好处多多,提供的方便的操作函数,类继承机制,MV*等,让我们能够快速开发,然而我们应该清楚这些框架都是基于浏览器原生api的封装, ...

  10. Redis缓存相关

    Redis缓存服务搭建及实现数据读写 RedisHelper帮助类 /// <summary> /// Redis 帮助类文件 /// </summary> public cl ...