Deutsche Bank | OA | Help Needed
Anonymous User
2331

There was a simple question asked for the online assesment.
Given a building with N floors in how many ways can you reach from the 0th floor to the Nth floor given at a time you can take 1 step , 2 steps or 3 steps. You can take 1 or 2 steps any number of times but you can take 3 steps at most K times.
Input N K

Output - Number of ways you can reach floor N

I had written the following program but kept getting WA.
Could anyone help me figure out how to write the bottom up DP for this question?

#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;

#define rep(i,a,b) for(ll i =a ;i <= b;i++)

typedef vector<int> vi;
int main()
{
	//ifstream cin("input.txt");
	ll n,k;
	cin>>n>>k;
	vvi dp(n+1, vi(k+1, 0));
	
	return 0;
	rep(i, 0, k){
		dp[1][i] = 1;
		dp[2][i] = 2;
	}
	rep(i, 3,n)
		dp[i][0] = dp[i-1][0] + dp[i-2][0];

	rep(i, 3, n)
		rep(j,1,k)
			dp[i][k] = dp[i-1][k] + dp[i-2][k] + dp[i-3][j-1];
	
	cout<<dp[n][k];
}
Comments (11)