UVA 10157 Expressions
来源:互联网 发布:时时彩后二缩水软件 编辑:程序博客网 时间:2024/06/08 17:42
题意:老是RE,看了题解:点击打开链接
#include <cstdio>#include <cstring>using namespace std;const int LEN=100;const int NMAX=300;const int DMAX=150;int f[NMAX+1][DMAX+1][LEN];bool vis[NMAX+1][DMAX+1];void add(int a[],int b[]){ int c = 0; for(int i = 0; i < LEN; ++i){ int n = (c+a[i]+b[i]) % 10; c = (c+a[i]+b[i]) / 10; a[i] = n; }}void sub(int a[],int b[]){ int c = 0; for (int i = 0; i < LEN; i++){ a[i] = a[i] - b[i] + c; if (a[i] < 0){ a[i] += 10; c = -1; } else c = 0; }}void mul(int a[],int b[]){ int c[LEN]; memset(c,0,sizeof(c)); int I = LEN; while(--I >= 0 && a[I] == 0); //去除前导0 ++I; int K = LEN; while(--K >= 0 && b[K] == 0); ++K; for(int i = 0; i < I; ++i) for(int k = 0; k < K && i+k < LEN; ++k) c[i+k] += a[i]*b[k]; int d = 0; for(int i = 0; i < LEN; ++i) { int n = (d + c[i]) % 10; d = (d + c[i]) / 10; c[i] = n; } memcpy(a,c,sizeof(c));}void print(int a[]){ int i = LEN; while(--i > 0 && a[i]==0); for (int j = i; j >= 0; j--) printf("%d",a[j]); printf("\n");}void cal(int n,int d){ if(vis[n][d]) return; vis[n][d] = 1; if(n % 2 == 1) return; if(n == 0){ f[n][d][0]=1; return; } if(d == 0) return; int t[LEN]; for(int i = 0; i < n; i+=2){ cal(i,d); cal(n-2-i,d-1); memcpy(t,f[i][d],sizeof(t)); mul(t,f[n-2-i][d-1]); add(f[n][d],t); }}int main(){ int n,d; while(scanf("%d%d",&n,&d)==2){ if(d==0 && n==0){ printf("1\n"); continue; } else if(d == 0){ printf("0\n"); continue; } else if(n == d*2){ printf("1\n"); continue; } memset(f,0,sizeof(f)); memset(vis,0,sizeof(vis)); cal(n,d); //计算深度不超过d的可能 cal(n,d-1); int ans[LEN]; memcpy(ans,f[n][d],sizeof(ans)); sub(ans,f[n][d-1]); print(ans); } return 0;}
- uva 10157 expressions
- UVA 10157 Expressions
- uva 10157 - Expressions(dp)
- UVa 10157 - Expressions
- uva 10157Expressions
- UVa Problem Solution: 10157 - Expressions
- Expressions uva
- UVa Problem 10157 Expressions (括号表达式)
- UVa 10157 Expressions (组合数学&高精度)
- UVa:10157 Expressions(动态规划+大数)
- UVA题目10157 - Expressions(DP+高精度)
- UVa 11234 Expressions
- uva 11234 - Expressions
- UVa 11234 Expressions
- uva 11234 - Expressions
- UVa 11234 - Expressions
- UVA 11234 - Expressions
- UVa 11234 - Expressions
- UIView无限旋转动画的实现
- 网盘的兴起及其向云存储的转化
- CentOS6.4双网卡修改默认网关
- mysql联合惟一键设置
- java 线程同步
- UVA 10157 Expressions
- Hadoop 2.2.0 libhadoop.so的disabled stack guard问题
- MySQL日期数据类型、时间类型使用总结
- 堆排序原理及算法实现
- Link-local Multicast Name Resolution
- Linux 上的基础网络设备详解
- 一个合格的程序员应该读过哪些书
- HDU 2524 矩形A + B
- MySQL 建表语法