第一题组合数学题。可以使用递推,设1与其他各数分别连边,假设N=3;若1-4,则圆分成两部分计数,此时可以利用乘法原理。(高精度)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string> using namespace std; const int maxn = 200;
struct bign {
int len, s[maxn]; bign() {
memset(s, 0, sizeof(s));
len = 1;
} bign(int num) {
*this = num;
} bign(const char* num) {
*this = num;
} bign operator =(int num) { //直接以整数赋值
char s[maxn];
sprintf(s, "%d", num);
*this = s;
return *this;
} bign operator =(const char* num) { //以字符串赋值
len = strlen(num);
for(int i = 0; i < len; i++)
s[i] = num[len - i - 1] - '0';
return *this;
} string str() const { //将bign转化成字符串
string res = "";
for(int i = 0; i < len; i++)
res = (char) (s[i] + '0') + res;
if(res == "")
res = "0";
return res;
} bign operator +(const bign& b) const { //重载+号运算
bign c;
c.len = 0;
for(int i = 0, g = 0; g || i < max(len, b.len); i++) {
int x = g;
if(i < len) x += s[i];
if(i < b.len) x += b.s[i];
c.s[c.len++] = x % 10;
g = x / 10;
}
return c;
} void clean() { //去掉前到0
while(len > 1 && !s[len - 1])
len--;
} bign operator *(const bign& b) { //重载*号运算
bign c;
c.len = len + b.len;
for(int i = 0; i < len; i++)
for(int j = 0; j < b.len; j++)
c.s[i + j] += s[i] * b.s[j];
for(int i = 0; i < c.len - 1; i++) {
c.s[i + 1] += c.s[i] / 10;
c.s[i] %= 10;
}
c.clean();
return c;
} bign operator -(const bign& b) { //重载-号运算
bign c;
c.len = 0;
for(int i = 0, g = 0; i < len; i++) {
int x = s[i] - g;
if(i < b.len)
x -= b.s[i];
if(x >= 0)
g = 0;
else {
g = 1;
x += 10;
}
c.s[c.len++] = x;
}
c.clean();
return c;
} bool operator <(const bign& b) const { //重载<号运算
if(len != b.len)
return len < b.len;
for(int i = len - 1; i >= 0; i--)
if(s[i] != b.s[i])
return s[i] < b.s[i];
return false;
} bool operator >(const bign& b) const { //重载>号运算
return b < *this;
} bool operator <=(const bign& b) { //重载<=号运算
return !(b > *this);
} bool operator ==(const bign& b) { //重载>=号运算
return !(b < *this) && !(*this < b);
} bign operator +=(const bign& b) { //重载+=号运算
*this = *this + b;
return *this;
}
}; istream& operator >>(istream &in, bign& x) { //重载输入运算符
string s;
in >> s;
x = s.c_str();
return in;
} ostream& operator <<(ostream &out, const bign& x) { //重载输出运算符
out << x.str();
return out;
} bign ans[210]; void initial(){
ans[2]=1;
ans[4]=2;
for(int i=5;i<=200;i++){
ans[i]=ans[i-2]+ans[i-2];
for(int j=3;j<i;j++){
ans[i]=ans[i]+ans[j-2]*ans[i-j];
}
}
} int main(){
initial();
int n;
while(scanf("%d",&n),n!=-1){
cout<<ans[2*n]<<endl;
}
return 0;
}

  

POJ 2084的更多相关文章

  1. POJ 2084 Catalan数+高精度

    POJ 2084 /**************************************** * author : Grant Yuan * time : 2014/10/19 15:42 * ...

  2. POJ 2084 Game of Connections

    卡特兰数. #include<stdio.h> #include<string.h> ; ; void mul(__int64 a[],int len,int b) { int ...

  3. (组合数学3.1.2.2)POJ 2084 Game of Connections(卡特兰数公示的实现)

    package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class POJ_2084 ...

  4. POJ 2084 Game of Connections(卡特兰数)

    卡特兰数源于组合数学,ACM中比较具体的使用例子有,1括号匹配的种数.2在栈中的自然数出栈的种数.3求多边形内三角形的个数.4,n个数围城圆圈,找不相交线段的个数.5给定n个数,求组成二叉树的种数…… ...

  5. POJ 2084 Catalan

    Game of Connections Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8772   Accepted: 43 ...

  6. poj——2084  Game of Connections

    Game of Connections Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8664   Accepted: 42 ...

  7. POJ 2084 Game of Connections 卡特兰数

    看了下大牛们的,原来这题是卡特兰数,顺便练练java.递归式子:h(0)=1,h(1)=1   h(n)= h(0)*h(n-1) + h(1)*h(n-2) + ... + h(n-1)h(0) ( ...

  8. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  9. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

随机推荐

  1. [HTML 5] More about ARIA Relationships

  2. SSH学习之中的一个 OpenSSH基本使用

    在Linux系统中.OpenSSH是眼下最流行的远程系统登录与文件传输应用,也是传统Telenet.FTP和R系列等网络应用的换代产品. 当中,ssh(Secure Shell)能够替代telnet. ...

  3. VC版超级记事本

    这是学习VC时的一个大作业,超级记事本.突然发现了,传上来供大家学习參考! 一.  功能需求: 1. 能在原有像记事本程序的基础上加入很多其它功能: 1).可以改变背景颜色. 2).可以改变字体颜色. ...

  4. 0x06 倍增

    这东西太玄学了我真是不太会... 对于这道例题,很容易看出最大值必然是最大减最小,次大减次小…… 常规的贪心思想,分的个数一样,总长度越大越好.其实我的第一想法是二分右端点..但是只有40,至今没有搞 ...

  5. Oracle 11G R2 用exp无法导出空表解决方法

    四.  Oracle 10g以后增加了expdp和impdp工具,用此工具也可以导出空的表 oracleexpdp/impdp 用法详解 1)  创建逻辑目录,该命令不会在操作系统创建真正的目录,最好 ...

  6. MSSQL执行大脚本文件时,提示“内存不足”的解决办法

    导出了一个脚本文件,将近900M,回来往sql studio一丢,报了个内存不足,然后就有了此文.. 问题描述: 当客户服务器不允许直接备份时,往往通过导出数据库脚本的方式来部署-还原数据库, 但是当 ...

  7. RTSP/RTP 媒体传输和控制协议

    1 前言 本文档主要描述了 NewStream Vision 系统中前端视频服务器(DVR, 网络摄像机), 中心转发服务器以及客户端之间的多媒体通信以及控制协议. 本协议主要基于标准的 IETE 的 ...

  8. 【转】在IIS上部署你的ASP.NET Core项目

    概述 与ASP.NET时代不同,ASP.NET Core不再是由IIS工作进程(w3wp.exe)托管,而是使用自托管Web服务器(Kestrel)运行,IIS则是作为反向代理的角色转发请求到Kest ...

  9. Chosen:Select 选择框的华丽变身

    HTML Form 表单里的各种组件,例如文本输入框,textarea,按钮等,都可以通过CSS或其它技术进行美化,让它们看起来很漂亮了,唯独下拉列表选项框(select box),不管你怎么做,它摆 ...

  10. 格式化日期字符串 FormatSettings使用

    如果 你想要得到 YYYY-MM/DD 这样的字符串 你肯定说这太简单了  直接 ShowMessage(FormatDateTime('YYYY-MM/DD',now)); 运行结果 YYYY-MM ...