hdu 1133 Buy the Ticket
2011-12-03 16:00
357 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1133
我的代码
我的代码
#include <stdio.h> #include <string.h> const int N=101,base=10000000; int f ; void plus(int *a,int *b) { int i; if (b[0]>a[0]) a[0]=b[0]; for (i=1;i<=a[0];i++) { a[i]+=b[i]; if (a[i]>=base) { a[i]-=base; a[i+1]++; } if (a[a[0]+1]>0) a[0]++; } } void mult(int *a,int b) { int i; a[1]*=b; for (i=2;i<=a[0];i++) { a[i]=a[i]*b+a[i-1]/base; a[i-1]%=base; } while (a[a[0]]>=base) { a[0]++; a[a[0]]=a[a[0]-1]/base; a[a[0]-1]%=base; } } void printbn(int *a) { int i; printf("%d",a[a[0]]); for (i=a[0]-1;i>0;i--) printf("%07d",a[i]); printf("\n"); } int main() { int i,j,k; memset(f,0,sizeof(f)); for (i=1;i<N;i++) f[i][0][0]=f[i][0][1]=1; for (i=1;i<N;i++) for (j=1;j<=i;j++) { plus(f[i][j],f[i-1][j]); plus(f[i][j],f[i][j-1]); } for (i=0;i<N;i++) for (j=0;j<=i;j++) { for (k=1;k<=i;k++) mult(f[i][j],k); for (k=1;k<=j;k++) mult(f[i][j],k); } int c=0,n,m; while (scanf("%d%d",&n,&m) && (n||m)) { printf("Test #%d:\n",++c); printbn(f [m]); } return 0; }
相关文章推荐
- HDU 1133 Buy the Ticket
- Hdu 1133 Buy the Ticket[卡特兰数小变形]
- hdu 1133 Buy the Ticket
- HDU 1133 Buy the Ticket 卡特兰数
- Buy the Ticket HDU - 1133 (递推+动态规划+组合)
- HDU 1133 Buy the Ticket
- hdu 1133 Buy the Ticket
- hdu 1133 Buy the Ticket(Catalan数)
- HDU 1133 Buy the ticket catalan 数
- hdu 1133 Buy the Ticket
- hdu 1133 Buy the Ticket 卡特兰数+递推+java
- hdu 1133 Buy the Ticket(递推+精度精算)
- hdu 1133 Buy the Ticket 卡特兰数+递推+java
- hdu 1133 Buy the Ticket
- 【HDU】1133 - Buy the Ticket(BigDecimal & 组合数学 & 递推)
- HDU 1133 - Buy the Ticket 【动态规划+组合 ~递推 偶遇 卡特兰】
- HDU 1267 下沙的沙子有几粒? + HDU 1133 Buy the Ticket 递推 *
- HDU-1133-Buy the Ticket
- HDU 1133 Buy the Ticket
- hdu 1133 Buy the Ticket