Uva 6177 The King's Ups and Downs

Sample Input

4
1 1
2 3
3 4
4 20

Sample Output

1 l
2 4
3 10
4 740742376475050
#include<iostream>
#include<string>
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<<a<<' '<<ans[b]<<endl; 
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/UltraSurreal/article/details/81485713