ICPC 2017 Japan Tsukuba . Secret of Chocolate Poles(动态规划)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/XxxxxM1/article/details/82263390

问题 A: Secret of Chocolate Poles

时间限制: 1 Sec  内存限制: 128 MB
提交: 168  解决: 74
[提交] [状态] [讨论版] [命题人:admin]

题目描述

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.
 

输入

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 the number of possible distinct patterns.

样例输入

5 3

样例输出

6
#include<bits/stdc++.h>
using namespace std;
#define maxn 110
#define M(a) memset(a,0,sizeof(a))
#define ll long long
 
int main()
{
    ll l,k;
    while(cin>>l>>k)
    {
        ll ans=0,dp[maxn][2];
        M(dp);
        dp[0][1]=1;
        for(int i=1; i<=l; i++){
            dp[i][2]=dp[i-1][1];  //黑
            dp[i][1]=dp[i-1][2];  //白
            if(i>=k) dp[i][2]+=dp[i-k][1];
        }
         for(int i=1; i<=l; i++){
            ans+=dp[i][2];
        }
        cout<<ans<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/XxxxxM1/article/details/82263390
今日推荐