博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Aizu-1378- ICPC Asia 2017-Secret of Chocolate Poles
阅读量:5840 次
发布时间:2019-06-18

本文共 2520 字,大约阅读时间需要 8 分钟。

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 

 

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

 

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

#include 
#include
#include
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;}

 

转载于:https://www.cnblogs.com/gaojinmanlookworld/p/10586862.html

你可能感兴趣的文章
选择排序
查看>>
SQL Server 数据库的数据和日志空间信息
查看>>
前端基础之JavaScript
查看>>
自己动手做个智能小车(6)
查看>>
自己遇到的,曾未知道的知识点
查看>>
P1382 楼房 set用法小结
查看>>
分类器性能度量
查看>>
docker 基础
查看>>
写一个bat文件,删除文件名符合特定规则,且更改日期在某
查看>>
我的友情链接
查看>>
写Use Case的一种方式,从oracle的tutorial抄来的
查看>>
【C#】protected 变量类型
查看>>
Ubuntu解压
查看>>
爬虫_房多多(设置随机数反爬)
查看>>
藏地密码
查看>>
爬虫去重(只是讲了去重的策略,没有具体讲实现过程,反正就是云里雾里)...
查看>>
react中将px转化为rem或者vw
查看>>
8816
查看>>
avcodec_open2()分析
查看>>
何如获取单选框中某一个选中的值
查看>>