关闭

UVA 10790

标签: uva
189人阅读 评论(0) 收藏 举报
分类:
Thinking : It's a quite easy problem if you can find the relationship between P(a,b) and P(a-1,b) or P(a,b-1). 
Based on our math knowledge  and observation from the picture, we can know that P(a,b) = P(a-1,b) + (a-1)*(b*(b-1)/2).








AC code:

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define epsilon 1.0e-6
#define lli long long int
using namespace std;
//lli P[20005][20005];
lli parent(lli a,lli b)
{
	if (a == 1 || b == 1)
		return 0;
	return parent(a - 1, b) + (a - 1)*(b*(b - 1)) / 2;
}

int main()
{
	lli a, b;
	int T = 0;

	while (1)
	{
		T++;
		scanf("%lld%lld", &a, &b);
		if (a == 0 && b == 0)
			break;
		lli ans = parent(a, b);
		printf("Case %d: %lld\n", T, ans);
	}

	return 0;

}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3362次
    • 积分:276
    • 等级:
    • 排名:千里之外
    • 原创:25篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条