poj 3181

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

const int maxn = 1100;

__int64  a[maxn], b[maxn], inf;
int n, k;

int main()
{
	int i, j;
	inf = 1;
	for (i=0; i<18; i++)	inf *= 10;
	scanf("%d %d", &n, &k);
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	a[0] = 1;
	for (i=1; i<=k; i++)
		for (j=1; j<=n; j++)
		{
			if (j < i) continue;
			b[j] = b[j] + b[j-i] + (a[j] + a[j-i]) / inf;//这其实是相当于高精度处理的,当时就一直A不掉
			a[j] = (a[j] + a[j-i]) % inf;
		}
	if (b[n]) printf("%I64d", b[n]);
	printf("%I64d\n", a[n]);
	return 0;
}

你可能感兴趣的:(dp)