UVA 10790

原创 2016年06月01日 14:34:55
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;

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

UVA - 10790 How Many Points of Intersection?

We have two rows. There are a dots on the toprow and b dots on the bottom row. We draw line segment...

UVA10790 How Many Points of Intersection?

How Many Points of Intersection?  We have two rows. There are a dots on the toprow and b...

uva 10790 - How Many Points of Intersection?

How Many Points of Intersection?  We have two rows. There are a dots on the top row and b ...

uva10790

/* 虽然这道题不是很难,还是wa了一次,以前没用过longlong型的数据啊!!但这题还是令人长自信,因为我的推理过程没用到任何高深的数学公式、定理等等 题目大意 给定2条平行的直...

uva 10790 How Many Points of Intersection?

10790 How Many Points of Intersection? We have two rows. There are a dots on the top row and b dots...

uva 10790 How Many Points of Intersection?

uva 10790 How Many Points of Intersection? 题目大意;告诉你两条线上的定点个数,将点与电间连线,求交点个数。 解题思路:不解释。有规律 #includ...

UVa 10790 How Many Points of Intersection?

How Many Points of Intersection?  We have two rows. There are a dots on the top row and b...

10790 - How Many Points of Intersection?

How Many Points of Intersection?  We have two rows. There are a dots on the top row and b dots ...
  • SIOFive
  • SIOFive
  • 2013年07月24日 11:39
  • 616

BNU10790:Periodic Table of Elements

元素周期表最早由俄国的门捷列夫发明,起初只有不到100种元素,随着科学技术的进步,新发现的元素不断地被填入表中,目前科学家们正在合成第119号元素。 对于一个新发现的元素,由于科学文献中总要被提...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:UVA 10790
举报原因:
原因补充:

(最多只允许输入30个字)