HDU——2067 小兔的棋盤
阿新 • • 發佈:2017-08-10
getchar() ios printf 最短路徑 解決 自己 rip efi several
Input
每次輸入一個數n(1<=n<=35),當n等於-1時結束輸入。
Output
對於每個輸入數據輸出路徑數,具體格式看Sample。
Sample Input
1
3
12
-1
Sample Output
1 1 2
2 3 10
3 12 416024
Author
Rabbit
Source
RPG專場練習賽
Recommend
lcy | We have carefully selected several similar problems for you: 2064 2065 1133 2068 1267
思路:
擴展卡特蘭數
不要忘了開 long long
代碼:
小兔的棋盤
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11004 Accepted Submission(s): 5569
#include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define N 100 using namespace std; int n,tot; long long h[N]; int read() { int x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1; ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘; ch=getchar();} return x*f; } int catelan() { h[0]=1,h[1]=1; for(int i=2;i<=40;i++) for(int j=1;j<=i;j++) h[i]=h[j-1]*h[i-j]+h[i]; } int main() { catelan(); while(1) { n=read();tot++; if(n==-1) break; printf("%d %d %I64d\n",tot,n,2*h[n]); } return 0; }
HDU——2067 小兔的棋盤