yipo
11/22/2015 - 8:17 AM

Bar Codes

Bar Codes

#include <vector>
#include <algorithm>
#include <numeric>
#include <iostream>
using namespace std;

int64_t bc(int n,int k,int m) {
	vector<int64_t> dp(1+n,0);

	auto safe_access=[&](int i) {
		return (i>0)?dp[i]:0;
	};

	k--;
	fill_n(dp.begin()+1,m,1);

	while (k--) {
		partial_sum(dp.begin(),dp.end(),dp.begin());
		for (int i=n;i>0;i--) dp[i]=dp[i-1]-safe_access(i-1-m);
	}
	return dp[n];
}

int main() {
	int n,k,m;
	while (cin>>n>>k>>m) cout<<bc(n,k,m)<<endl;
	return 0;
}