第一题组合数学题。可以使用递推,设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. I - Agri-Net

    I - Agri-Net poj 1258 注意:多组数据输入. #include<cstdio> #include<cstring> #include<iostream ...

  2. MQTT---HiveMQ源代码具体解释(八)Netty-WebSocket

    源博客地址:http://blog.csdn.net/pipinet123 MQTT交流群:221405150 基于netty实现Webscoket相对来说就是相当简单,所以本讲中就不搞太复杂的了,给 ...

  3. 假设让我又一次设计一款Android App

    转载请注明出处: 本文来自aspook的博客:http://blog.csdn.net/ahence/article/details/47154419 开发工具的选择 开发工具我将选用Android  ...

  4. CentOS6.5下安装远程桌面服务端软件VNC Server

    VNC 使您能够远程訪问和控制您的计算机从还有一计算机或移动设备上,不管你在世界的不论什么地方. 常见的使用情形,包含给同事和朋友提供桌面支持.远程管理您的服务器. 将 VNC Server部署到您想 ...

  5. linux网络启动报错

    报错信息: shutting down interface eth0: error:device "eth0" (/org/freedsktop/networkMaager/Dev ...

  6. Android 开源框架ViewPageIndicator 和 ViewPager 仿网易新闻客户端Tab标签

    转载请注明出处:http://blog.csdn.net/xiaanming/article/details/10766053 之前用JakeWharton的开源框架ActionBarSherlock ...

  7. oracle性能检测sql语句

    1. 监控事例的等待 select event,sum(decode(wait_Time,0,0,1)) "Prev",sum(decode(wait_Time,0,1,0)) & ...

  8. Fragment间相互调用并传值

    public class MainFragment extends Fragment { private static final String ARG_DATE="com.example. ...

  9. Spark RDD概念学习系列之RDD的五大特征

    不多说,直接上干货! RDD的五大特征 分区--- partitions 依赖--- dependencies() 计算函数--- computer(p,context) 分区策略(Pair RDD) ...

  10. .NET Datatable常用系列一

    Datatable常用系列一 一.用作集合存储数据: DataTable dt = new DataTable("action"); for (int i = 0; i < ...