hdu 1134 Game of Connections(卡特兰(Catalan)公式)
2009-08-15 20:28
495 查看
模型1:
有
2n
个不同的数排成一个圆圈,用
n
条直线将每两个数连接在一起,可以组成
n
对数。若要求连线不能相交,对于
2n
个数,问有多少种不同的方法。
递推式
卡特兰公式
an
=C(2n,n)/(n+1)=(4n-2)*(an-1
)/(n+1)
有
2n
个不同的数排成一个圆圈,用
n
条直线将每两个数连接在一起,可以组成
n
对数。若要求连线不能相交,对于
2n
个数,问有多少种不同的方法。
递推式
卡特兰公式
an
=C(2n,n)/(n+1)=(4n-2)*(an-1
)/(n+1)
#include <iostream> using namespace std; int p[105][20]; int main() { p[1][0]=1; p[1][1]=1; for(int i=2;i<=100;i++) { int m=4*i-2; int len=p[i-1][0]; for(int j=1;j<=len;j++) p[i][j]=p[i-1][j]*m; int left=0; for(int j=len;j>0;j--) { p[i][j]+=left*1000; left=p[i][j]%(i+1); p[i][j]=p[i][j]/(i+1); } for(int j=1;j<len;j++) { p[i][j+1]+=p[i][j]/1000; p[i][j]=p[i][j]%1000; } while(p[i][len]>=1000) { p[i][len+1]=p[i][len]/1000; p[i][len]=p[i][len]%1000; len++; } p[i][0]=len; } int n; while(scanf("%d",&n),n!=-1) { printf("%d",p [p [0]]); for(int i=p [0]-1;i>0;i--) { if(p [i]>=100) printf("%d",p [i]); else if(p [i]>=10) printf("0%d",p [i]); else printf("00%d",p [i]); } printf("/n"); } return 0; }
相关文章推荐
- [Catalan] HDU 1134 Game of Connections
- hdu 1134 game of connections(Catalan Number)
- HDU 1134 Game of Connections
- [ACM] hdu 1134 Game of Connections(大数+Catalan数)
- HDOJ HDU 1134 Game of Connections
- hdu 1134 Game of Connections(卡特兰数模板题)
- HDU1134 Game of Connections(大数乘法+打表)
- [ACM] hdu 1134 Game of Connections(大数+Catalan数)
- 高精度-HDU-1134-Game of Connections
- HDU ACM 1134 Game of Connections / 1130 How Many Trees?(卡特兰数)
- HDU 1134 Game of Connections
- hdu 1134 Game of Connections
- hdu1134 Game of Connections 卡特兰数(大数)
- hdu 题目1134 Game of Connections (卡塔兰数 catalan number)
- HDU 1134 Game of Connections
- HDU 1134 Game of Connections(Catalan + 大数)
- HDU 1134 Game of Connections
- hdu-1134-Game of Connections(卡特兰数 大数乘法除法)
- HDU 1134 Game of Connections
- HDU 1134 Game of Connections