Aizu - 1378 - Secret of Chocolate Poles (DP)

版权声明:沃斯里德小浩浩啊 https://blog.csdn.net/Healer66/article/details/82377551

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 11 cm thick, and the thick disks are kk 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 ll 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=5l=5 and k=3k=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 ll and kk to help her accomplish her secret mission.

Input

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

ll kk

Here, the maximum possible total thickness of disks in a pole is ll cm, and the thickness of the thick disks is kk cm. ll and kk are integers satisfying 1≤l≤1001≤l≤100 and 2≤k≤102≤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

题意:
黑块有厚有薄,白块只有薄的,总高度为L,

要求:黑白相间摆放,且最上最下需要为黑色,不超L

问有多少种摆法。

思路:

状态转移方程

 dp[i][0] = dp[i - 1][ 1 ]  高度为i的白块结尾的种数等于高度i-1黑块结尾的总数

 dp[i][1] = dp[i - k][0] + dp[i - 1][0],高度i的黑块结尾的种数是高度i-1和i-k的白块结尾的种数之和

#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 100+5;
int l,k;
ll dp[maxn][2];
int main()
{
    cin>>l>>k;
    memset(dp,0,sizeof dp);
    dp[0][0]=1;//初始情况,相当于白块结尾
    for(int i = 1; i <= l; i++)
    {
        dp[i][1]=dp[i-1][0];
        dp[i][0]=dp[i-1][1];
        if(i>=k)
        dp[i][1]+=dp[i-k][0];
    }
    ll ans  = 0;
    for(int i = 1; i <= l;i++ )
    {
        ans+=dp[i][1];
    }
    cout<<ans<<endl;

}

猜你喜欢

转载自blog.csdn.net/Healer66/article/details/82377551