Uva 6177 The King's Ups and Downs

Uva 6177 The King's Ups and Downs_第1张图片

Sample Input

4
1 1
2 3
3 4
4 20

Sample Output

1 l
2 4
3 10
4 740742376475050
#include
#include
typedef long long ll;
using namespace std;
ll dp[30][30];
ll ans[30];
void init()
{
	dp[1][1]=ans[1]=1;
	for(int i=2;i<=20;i++)
	{
		for(int j=2;j<=i;j++)
		{
			dp[i][j]=dp[i-1][i+1-j]+dp[i][j-1];
			ans[i]+=dp[i][j];
		}
		ans[i]<<=1; 
	}
}

int main()
{
	int T,a,b;
	cin>>T;
	init();
	while(T--)
	{
		cin>>a>>b;
		cout<

 

你可能感兴趣的:(DP,DP)