UVA 10790

来源:互联网 发布:js移除数组中某个元素 编辑:程序博客网 时间:2024/05/21 14:48
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 intusing 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