SOJ.SubDiagonal Paths

13062. SubDiagonal Paths

限制条件

时间限制: 1 秒, 内存限制: 256 兆

题目描述

You are to find all of the paths on the bottom diagonal of a n x n grid. The path must only go from lefttoright or bottomtotop. Given a dimension of the grid (ex. n = 4), specify the number of such paths (ex. solution = 14). 

输入格式

The input consists of a single integer n, the dimension of the square grid, 1 <= n <= 30, on each line. A zero will indicate the end of the input and should not be processed.

输出格式

For each input n, you should output the number of paths, as described above, that exist in an nxn grid, one per line.

样例输入

1
2
3
4
0

样例输出

1
2
5
14

题目来源

2014年每周一赛第十五场暨“指点传媒杯”第六届中山大学ICPC新手赛模拟赛


卡特兰数存在递推公式a[i]=((4*i-2)/(i+1))*a(i-1)(i>1)


#include
     
     
      
      
long long a[30];
using namespace std;
int main(){
	int n;
	a[1]=1;
	for(int i=2;i<31;i++)a[i]=((4.0*i-2)/(i+1.0))*a[i-1];
	while(1){
	cin>>n;
	if(n==0)break;
	else cout<
      
      
       
       <
       
       
      
      
     
     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值