一道比较简单的DP,注意存结果用long long,否则会溢出
#include<stdio.h>
int main()
{
int k, C;
long long dp[2001], sum[2001];
scanf("%d", &C);
for (k = 1; k <= C; k++)
{
int i, j, n, m;
scanf("%d %d", &n, &m);
for (i = 1; i <= m; i++)
{
dp[i] = 1;
sum[i] = i;
}
for (i = 2; i <= n; i++)
{
for (j = m; j > 0; j--)
dp[j] = sum[j / 2];
sum[1] = dp[1];
for (j = 2; j <= m; j++)
sum[j] = sum[j - 1] + dp[j];
}
printf("Case %d: n = %d, m = %d, # lists = %lld\n", k, n, m, sum[m]);
}
return 0;
}