Problem Description
Given a function f(a, b, c):
If a ≤ 0 or b ≤ 0 or c ≤ 0 the return value is 1;
If a > 20 or b > 20 or c > 20 the return value is f(20, 20, 20);
If a < b and b < c return f(a, b, c−1) + f(a, b−1, c−1) − f(a, b−1, c);
Otherwise it returns f(a−1, b, c) + f(a−1, b−1, c) + f(a−1, b, c−1) − f(a-1, b-1, c-1).
Seems like a simple function? Can you do it right?
Input
The input contains multiple sets of test data, for each set of test data:
The input has only one row of 3 integers a, b, c (a, b, c < 30).
Output
For each set of test data, output the computed result of the function.
Sample Input
1 1 1 2 2 2
Sample Output
2 4
Hint
#include <stdio.h>
#include <stdlib.h>
int p[21][21][21]={0};
int f(int a,int b,int c)
{
if(a<=0||b<=0||c<=0)
return 1;
if(a>20||b>20||c>20)return f(20,20,20);
if(p[a][b][c]) return p[a][b][c];
if(a<b&&b<c)
return p[a][b][c]=f(a,b,c-1)+f(a,b-1,c-1)-f(a,b-1,c);
else
return p[a][b][c]=f(a-1,b,c)+f(a-1,b-1,c)+f(a-1,b,c-1)-f(a-1,b-1,c-1);
}
int main()
{
int a,b,c;
while(scanf("%d%d%d",&a,&b,&c)!=EOF)
printf("%d\n",f(a,b,c));
return 0;
}