卡特兰数 BZOJ3907 网格 NOIP2003 栈
卡特兰数:主要是求排列组合问题
1:括号化矩阵连乘,问多少种方案
2:走方格,不能过对角线,问多少种方案
3:凸边型,划分成三角形
NOIP2003 栈
//#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
// #include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
// const double pi = acos(-1);
const LL MOD = 1e8;
const int N=<<;
// const LL p = 1e9+7;
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// } int main() {
int n;
LL f[]={};
scanf("%d",&n);
f[]=;f[]=;
for(int i=;i<=n;i++)
for(int j=;j<i;j++)
f[i]+=f[j]*f[i-j-];
printf("%I64d\n",f[n]);
return ;
}
BZOJ3907 网格
/**************************************************************
Problem: 3907
User: Tunix
Language: C++
Result: Accepted
Time:84 ms
Memory:944 kb
****************************************************************/ #include<cstdio>
#include<cstring> typedef long long LL; const int N=;
const LL mod=; int tot=,x[N],p[N],v[N]={};
LL a[],b[]; LL pow(LL x,int p) {
LL t=;for (;p;p>>=,x*=x) if (p&) t*=x;return t;
} void mul(LL a[],LL y) {
LL x=,&l=a[];
for (int i=;i<=l;i++) {
a[i]=a[i]*y+x;
x=a[i]/mod;
a[i]%=mod;
}
while (x) a[++l]=x%mod,x/=mod;
} void dec(LL a[],LL b[]) {
LL &l=a[];
for (int i=;i<=l;i++) {
if (a[i]<b[i]) a[i+]--,a[i]+=mod;
a[i]-=b[i];
}
while (!a[l]) l--;
} void getc(LL a[],int n,int m) {
memset(x,,sizeof x);
for (int i=;i<=n;i++) x[i]++;
for (int i=;i<=m;i++) x[i]--;
for (int i=;i<=n-m;i++) x[i]--;
for (int i=n;i>=;i--)
if (!v[i]) mul(a,pow(i,x[i]));
else x[v[i]]+=x[i],x[i/v[i]]+=x[i];
} void print(LL a[]) {
int l=a[];
printf("%lld",a[l]);
for (int i=l-;i>=;i--) printf("%08lld",a[i]);
printf("\n");
} int main() {
int n,m;
scanf("%d%d",&n,&m);
for (int i=;i<=n+m;i++) {
if (!v[i]) p[++tot]=i;
for (int j=,k;j<=tot,(k=p[j]*i)<=n+m;j++) {
v[k]=p[j];
if (i%p[j]==) break;
}
}
a[]=a[]=b[]=b[]=;
getc(a,n+m,n);
getc(b,n+m,n+);
dec(a,b);
print(a);
return ;
}
卡特兰数 BZOJ3907 网格 NOIP2003 栈的更多相关文章
- hdu5816 卡特兰数+dp
		
题意:共n张无中生有,m张攻击牌.每张攻击牌攻击力已知,敌方有p点血.随机洗牌.游戏开始,己方抽取一张手牌,若是无中生有则可再抽两张牌.求能在第一回合内将敌方杀死的概率. n+m <= 20, ...
 - [NOIP2003]栈 题解(卡特兰数)
		
[NOIP2003]栈 Description 宁宁考虑的是这样一个问题:一个操作数序列,从1,2,一直到n(图示为1到3的情况),栈A的深度大于n. 现在可以进行两种操作: 1.将一个数,从操作数序 ...
 - bzoj3907 网格 & bzoj2822 [AHOI2012]树屋阶梯——卡特兰数+高精度
		
题目:bzoj3907:https://www.lydsy.com/JudgeOnline/problem.php?id=3907 bzoj2822:https://www.lydsy.com/Jud ...
 - BZOJ3907 网格 卡特兰数
		
题目描述 某城市的街道呈网格状,左下角坐标为A(0, 0),右上角坐标为B(n, m),其中n >= m. 现在从A(0, 0)点出发,只能沿着街道向正右方或者正上方行走,且不能经过图示中直线左 ...
 - NOIP2003pj栈[卡特兰数]
		
题目背景 栈是计算机中经典的数据结构,简单的说,栈就是限制在一端进行插入删除操作的线性表. 栈有两种最重要的操作,即pop(从栈顶弹出一个元素)和push(将一个元素进栈). 栈的重要性不言自明,任何 ...
 - 出栈顺序 与 卡特兰数(Catalan)的关系
		
一,问题描述 给定一个以字符串形式表示的入栈序列,请求出一共有多少种可能的出栈顺序?如何输出所有可能的出栈序列? 比如入栈序列为:1 2 3 ,则出栈序列一共有五种,分别如下:1 2 3.1 3 2 ...
 - 洛谷 p1044 栈 【Catalan(卡特兰数)】【经典题】
		
题目链接:https://www.luogu.org/problemnew/show/P1044 转载于:https://www.luogu.org/blog/QiXingZhi/solution-p ...
 - CH1102 火车进出栈问题(高精/卡特兰数)
		
描述 一列火车n节车厢,依次编号为1,2,3,-,n.每节车厢有两种运动方式,进栈与出栈,问n节车厢出栈的可能排列方式有多少种. 输入格式 一个数,n(n<=60000) 输出格式 一个数s表示 ...
 - 【讲●解】火车进出栈类问题 & 卡特兰数应用
		
火车进出栈类问题详讲 & 卡特兰数应用 引题:火车进出栈问题 [题目大意] 给定 \(1\)~\(N\) 这\(N\)个整数和一个大小无限的栈,每个数都要进栈并出栈一次.如果进栈的顺序为 \( ...
 
随机推荐
- 彻底弄懂LSH之simHash算法
			
马克·吐温曾经说过,所谓经典小说,就是指很多人希望读过,但很少人真正花时间去读的小说.这种说法同样适用于“经典”的计算机书籍. 最近一直在看LSH,不过由于matlab基础比较差,一直没搞懂.最近看的 ...
 - PAT-乙级-1002. 写出这个数 (20)
			
1002. 写出这个数 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 读入一个自然数n,计算其各位数字 ...
 - XoftSpy 4.13的注册算法分析
			
[标题]XoftSpy 4.13的注册算法分析 [作者]forever[RCT] [语言]VC [工具]ida4.6,ollydbg1.1 [正文] 这个软件的算法很简单,正好拿来做逆向分 ...
 - c++ ANSI、UNICODE、UTF8互转
			
static std::wstring MBytesToWString(const char* lpcszString); static std::string WStringToMBy ...
 - 2.Adding a Controller
			
MVC stands for model-view-controller. MVC is a pattern for developing applications that are well ar ...
 - [itint5]支持删除的后继查询
			
http://www.itint5.com/oj/#49 这一题一开始想到是用HashSet+链表来做,链表记录prev和next.这样也可以,后来看到都是连续的整数,而且交流了一下觉得可以用类似并查 ...
 - IIS8报错 403 404
			
当IIS报403错误,而打开目录浏览权限后,又出404错误,这种错误很可能是.net的版本安装问题 注意勾选上asp.net4.5
 - 概率图模型之有向图与无向图之间的关系  I map D map perfect map(完美图) 概念
			
我们已经讨论了有向图和无向图框架下的概率模型,那么我们有必要讨论一下它们二者的关系.
 - 【原创】oracle的tpc-c测试及方法
			
大家好,很高兴来到博客园分享自己的所见所得.希望和大家多多交流,共同进步. 本文重点在于简介使用BenchmarkSQL对oracle进行tpcc的测试步骤,只是一个简单入门的过程. 开源测试工具:B ...
 - 在Vim里使用gtags-cscope
			
用Vundle安装好gtags-cscope后,要在vimrc里添加如下设置: " cscopeset cscopetag " 使用 cscope ...