题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5673

  题目描述: 一个人从原点开始向右走, 要求N秒后回到原点, 且过程中不能到负半轴, 人有两种操作, 走动或者停止, 问总共有多少种方案?

  解题思路: 类似于括号匹配问题, 和那个我去年这个时候接触到的最裸的不能越过对角线的正方形走到对角问题, 卡特兰数, 从2开始枚举走动步数, 然后剩下的就是不动的步数, 用不动的步数做个填充就可以了, 设计到取模, 需要逆元

  代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iterator>
#include <cmath>
#include <algorithm>
#include <stack>
#include <deque>
#include <map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,-0x3f,sizeof(a))
#define fi(n) for(i=0;i<n;i++)
#define fj(m) for(j=0;j<m;j++)
#define sca(x) scanf("%d",&x)
#define ssca(x) scanf("%s",x)
#define scalld(x) scanf("%I64d",&x)
#define print(x) printf("%d\n", x)
#define printlld(x) printf("%I64d\n",x)
#define de printf("=======\n")
#define yes printf("YES\n")
#define no printf("NO\n")
typedef long long ll;
using namespace std;const int mod = 1e9+7;
const int maxn = 1e6+100;ll inv[maxn];
ll h[maxn];
ll c[maxn];void init() {inv[1] = 1;for( int i = 2; i < maxn; i++ ) { // 预处理逆元inv[i] = (mod - mod / i) * inv[mod%i] % mod;}
}int main() {init();int t;int n;h[0] = h[1] = 1;for( int i = 2; i < maxn; i++ ) { // 卡特兰数h[i] = h[i-1] * (4*i-2)%mod * inv[i+1] % mod;}sca(t);while( t-- ) {sca(n);ll ans = 1;c[0] = 1;for( int i = 1; i <= n; i++ ) { // 组合数c[i] = c[i-1] * (n-i+1) % mod * inv[i] % mod;}for( int i = 1; ; i++ ) {int k = n - (i<<1);if( k < 0 ) break;ans = (ans + h[i] * c[k]) % mod;}printf( "%lld\n", ans );}return 0;
}

View Code

  思考: 很裸的卡特兰数, 组合数学很有意思, 然后就是说我感觉现在需要开始整理一下板子了, 比如说这个, 还有那个神题等等, 洗完澡回来再说, 我好菜啊

http://acm.hdu.edu.cn/showproblem.php?pid=5673

转载于:https://www.cnblogs.com/FriskyPuppy/p/7429331.html

HDU 5673 Robot 卡特兰数相关推荐

  1. hdu 1023 大数 卡特兰数

    卡特兰数 JAVA大数 import java.util.*; import java.math.*; public class Main {public static void main(Strin ...

  2. HDU 3240 Counting Binary Trees 数论-卡特兰数

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3240 卡特兰数递推公式h(i)=h(i-1)*(4*i-2)/(i+1) 如果直接算每一步,然后mo ...

  3. 【HDU - 1134 】Game of Connections(JAVA大数加法,卡特兰数)

    题干: This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, ... , 2n - ...

  4. hdu 1134 卡特兰数(大数模板)

    卡特兰数 递推公式: C(n)=C(2n,n)/(n+1)  即用数组表示为c[i]=c[i-1]*(4*i-2)/(i+1); 一般形式 直接 表达 c[1]=1; for(i=2;i<40; ...

  5. HDU 3723 Delta Wave(卡特兰数+大数)

    题意:从坐标(0, 0)到(n, 0)的折线,这条折线每向右延伸一个单位长度,高度要么不变,要么+1,要么-1,(不能到y=0以下)已知n,求这种折线种数 思路:我们知道上升和下降的次数要一样,而这就 ...

  6. HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  7. 卡特兰数 BZOJ3907 网格 NOIP2003 栈

    卡特兰数 卡特兰数2 卡特兰数:主要是求排列组合问题 1:括号化矩阵连乘,问多少种方案 2:走方格,不能过对角线,问多少种方案 3:凸边型,划分成三角形 4:1到n的序列进栈,有多少种出栈方案 NOI ...

  8. 信奥中的数学:斯特林数、卡特兰数

    P1287 盒子与球(球不同 盒不同 不允许有空盒) 盒子与球 - 洛谷 第二类斯特林数总结 第二类斯特林数总结 - _zjz 的博客 - 洛谷博客 P4091 [HEOI2016/TJOI2016] ...

  9. 2017百度之星程序设计大赛 - 资格赛【1001 Floyd求最小环 1002 歪解(并查集),1003 完全背包 1004 01背包 1005 打表找规律+卡特兰数】...

    度度熊保护村庄 Accepts: 13 Submissions: 488 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3276 ...

最新文章

  1. OpenCV 遇到的问题
  2. ActiveX 控件导入程序
  3. 如何判断数组所有数都不等于一个数_【每日算法Day 91】求解数组中出现次数超过1/3的那个数
  4. 天兔(Lepus)监控邮件推送安装配置
  5. Executor 执行器接口笔记
  6. http://www.shengshiyouxi.com
  7. java 操作redis
  8. java中map的遍历方法_Java中Map的三种遍历方式
  9. 中国省份数据字典表---自用
  10. 启动器Android标准,【转】各款安卓启动器评测(之我见)
  11. Go语言 —— 前景
  12. Python爬虫(二)——urllib库,Post与Get数据传送区别,设置Headers,urlopen方法,简单爬虫
  13. 关于VSCode安装 python 语法检测器插件 pylint 配置(Mac)
  14. 5G通信中的TDL模型
  15. MQTT 客户端收发 MQTT 消息
  16. 用HTML+CSS做成的一个简单网页(小兔鲜儿)
  17. php安全新闻早八点-Microdoor-第四季
  18. 湖南无线数字电服务器,戴尔服务器搭建湖南省高校数字化图书馆
  19. OFDM水声通信基础
  20. 【图形学】CPU 与 GPU

热门文章

  1. C#连接基于Java开发IM——Openfire
  2. ubuntu设置静态ip
  3. DB Stack Overflow
  4. BZOJ3570 : DZY Loves Physics I
  5. android中AsyncTask和Handler对比
  6. 用手机EchoEcho问询朋友所在的位置
  7. java string fill_Java使用fill()数组填充的实现
  8. 什么是U-Boot以及如何下载U-Boot源码
  9. JDK 与 JRE区别
  10. 电脑技巧:微软电脑管家测试版发布,赶快来体验一下吧!