@cache defBC(n, k, m): if n == 0: # 沒有unit了,若還有bar則不滿足 return1if k == 0else0 if k == 1: # 只有1個bar,若滿足限制條件則有1種可能 return1if n <= m else0 res = 0 for x inrange(1, min(n, m)+1): res += BC(n-x, k-1, m) # 剩下n-x個units, k-1個bars, 每個bar最多還是m個units return res
whileTrue: try: n, k, m = map(int, input().split()) except EOFError: break print(BC(n, k, m))
#include<bits/stdc++.h> usingnamespace std; using LL = longlong; constint N = 55; #define endl '\n'
LL dp[N][N][N];
LL BC(int n, int k, int m){ if (dp[n][k][m] != -1) return dp[n][k][m]; // memoization if (n == 0) return k == 0; // 沒有unit了,若還有bar則不滿足 if (k == 1) return n <= m; // 只有1個bar,若滿足限制條件則有1種可能 LL res = 0; for (int x = 1; x <= min(n, m); ++x) { res += BC(n-x, k-1, m); // 剩下n-x個units, k-1個bars, 每個bar最多還是m個units } dp[n][k][m] = res; return res; }
intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k, m; memset(dp, -1, sizeof(dp)); while (cin >> n >> k >> m) { cout << BC(n, k, m) << endl; } return0; }