HDU1134 Game of Connections 高精度+DP
来源:互联网 发布:java乘法表代码 编辑:程序博客网 时间:2024/06/08 07:20
Problem Address:http://acm.hdu.edu.cn/showproblem.php?pid=1134
【思路】
dp状态转移:dp[i] = sum(dp[j]*dp[i-1-j]) [0<=j<i]
加上高精度乘法和加法。
【代码】
代码又颓了= =
看来得准备一个高精度的模板啊!
#include <iostream>using namespace std;const int maxn = 100;const int size = 100; struct num { int n[size]; int len; num() { memset(n, 0, sizeof(n)); len = 1; } }d[maxn+5];void multiply(num &t, num s){ int i,j; num a; for (i=0; i<t.len; i++) { for (j=0; j<s.len; j++) { a.n[i+j] += t.n[i] * s.n[j]; } } for (i=0; i<size-1; i++) { if (a.n[i]>=10) { a.n[i+1] += a.n[i]/10; a.n[i] = a.n[i]%10; } } for (i=size-1; i>=0; i--) { if (a.n[i]!=0) break; } a.len = i+1; if (a.len==0) a.len = 1; for (i=0; i<size; i++) { t.n[i] = a.n[i]; } t.len = a.len; } void add(num &t, num s){int i;num a;for (i=0; i<size-1; i++){a.n[i] += t.n[i] + s.n[i];} for (i=0; i<size-1; i++) { if (a.n[i]>=10) { a.n[i+1] += a.n[i]/10; a.n[i] = a.n[i]%10; } } for (i=size-1; i>=0; i--) { if (a.n[i]!=0) break; } a.len = i+1; if (a.len==0) a.len = 1; for (i=0; i<size; i++) { t.n[i] = a.n[i]; } t.len = a.len; }void output(num a) { int i;for (i=a.len-1; i>=0; i--) printf("%d", a.n[i]);printf("\n");} int main(){int i, j;d[0].n[0] = 1;d[0].len = 1;d[1].n[0] = 1;d[1].len = 1;for (i=2; i<=maxn; i++){num temp;for (j=0; j<i; j++){temp = d[j];multiply(temp, d[i-1-j]);add(d[i], temp);}}int n;while(scanf("%d", &n)!=EOF){if (n==-1) break;output(d[n]);}return 0;}
- HDU1134 Game of Connections 高精度+DP
- hdu1134-Game of Connections
- HDU1134 Game of Connections
- ZOJ 2424-Game of Connections-DP+高精度
- hdu1134 Game of Connections 卡特兰数(大数)
- hdu1134 Game of Connections(卡特兰数)
- hdu1134 Game of Connections(Catalan+高精)
- HDU1134 Game of Connections(大数乘法+打表)
- 高精度-HDU-1134-Game of Connections
- POJ2084—Game of Connections(c++高精度)
- hdu1134 Game of Connections(Catalan数, 顺便附上大数类模板)
- HDU1134——Game of Connections (大数乘法,除法)+ (卡特兰数列)
- HDU 1134 Game of Connections 高精度卡特兰数
- Poj 2084 Game of Connections(高精度卡特兰数)
- HDU 1134 Game of Connections (高精度卡特兰数)
- Game of Connections(标准卡特兰数及高精度)
- 1134 ---( Game of Connections )
- poj2084 Game of Connections
- 在Dialog(基本对话框)中使用BCMenu
- Linux C编程感想
- NSArray NSMutableArray
- 使用JavaEE开发的一个内部图书管理系统(1)
- grep用法好简单,看bird兄教你玩转grep
- HDU1134 Game of Connections 高精度+DP
- linux装机知识
- 拒绝平庸
- Android打开系统设置界面
- TextView小组件的使用--附带超链接和跑马灯效果
- poj_1163
- 欢迎加入!!!
- DirectFB配置信息
- 我的家庭私有云计划-1