Sicily 13062. SubDiagonal Paths

来源:互联网 发布:深圳网络诈骗被骗5万 编辑:程序博客网 时间:2024/05/22 06:22

13062. SubDiagonal Paths

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

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). 

Input

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.

Output

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

Sample Input

12340

Sample Output

12514

Problem Source

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

// Problem#: 13062// Submission#: 3412529// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <stdio.h>#include <iostream>#include <vector>#include <string>#include <stack>#include <iomanip>#include <algorithm>#include <queue>#include <functional>#include <map>#include <string.h>#include <math.h>#include <list>using namespace std;int main() {    std::ios::sync_with_stdio(false);    long long dp[35];    dp[0] = 1;    dp[1] = 1;    for (int i = 2; i <= 30; i++) {        dp[i] = 0;        for (int j = 0; j < i; j++) {            dp[i] += dp[j] * dp[i - 1 - j];        }    }    while (1) {        int pos;        cin >> pos;        if (pos == 0) break;        cout << dp[pos] << endl;    }    return 0;}                                 


0 0
原创粉丝点击