UVA - 10721 Bar Codes

题目大意:给出n,k和m,用k个1~m的数组成n,问有几种组成方法。


解题思路:简单dp,cnt[i][j]表示用i个数组成j, cnt[i][j] = ∑(1 ≤ t  ≤min(k, j)) cnt[i - 1][t].


#include <cstdio>

int main() {
	int n, k, m;
	while (scanf("%d%d%d", &n, &k, &m) != EOF) {
		long long DP[55][55] = {1};
		for (int i = 1; i <= k; i++)
			for (int j = 1; j <= m; j++)
				for (int r = j; r <= n; r++)
					DP[i][r] += DP[i-1][r-j];

		printf("%lld\n", DP[k][n]);
	}
	return 0;
}


你可能感兴趣的:(UVA - 10721 Bar Codes)