http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=1

【题解】:卡特兰数取模

h(n) = h(n-1)*(4*n-2)/(n+1)

这题我们公式选择错了,不过还是能AC的

因为要取模,应该选 h(n)=h(0)*h(n-1)+h(1)*h(n-2)+...+h(n-1)*h(0) (n>=2)

【code-java】:

 import java.math.BigInteger;
import java.util.Scanner; public class Main { public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger [] arr = new BigInteger[10100];
BigInteger temp;
arr[1] = new BigInteger("1");
for(int i=2;i<=10000;i++){
temp = new BigInteger(""+(4*i-2)+"");
arr[i] = arr[i-1].multiply(temp).divide(new BigInteger(""+(i+1)+""));
//System.out.println(arr[i]);
} while(cin.hasNextInt())
{
BigInteger a;
int n,i;
n=cin.nextInt();
System.out.println(arr[n].mod(new BigInteger("1000000007")));
}
}
}

【code-C++】:

 #include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
using namespace std; const int m=;
typedef long long LL; int n; void mul(LL &res,int k)
{
res=(res*k)%m;
} int ext_gcd(int a,int b,int &x,int &y)
{
int ret;
if(!b)
{
x=;y=;return a;
}
ret=ext_gcd(b,a%b,y,x);
y-=x*(a/b);
return ret;
} void chu(LL &res,int k)
{
if(k!=)
{
int x,y,temp;
temp=ext_gcd(k,m,x,y);
x=(x%m+m)%m;
res=(res*x)%m;
}
} LL arr[]; int main()
{
LL res=,l=;
arr[]=;
for(int i=;i<=;i++)
{
mul(res,*i-);
chu(res,i+);
l=res;
l=l%m;
arr[i]=l;
}
while(scanf("%d",&n)!=EOF)
{ printf("%lld\n",arr[n]);
}
return ;
}

Contest2037 - CSU Monthly 2013 Oct (problem B :Scoop water)的更多相关文章

  1. Contest2037 - CSU Monthly 2013 Oct (problem F :ZZY and his little friends)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=5 [题解]: 没想通这题暴力可以过.... [code]: #inclu ...

  2. Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)

    [题解]: 最短路径问题,保证距离最短的同时,学妹权值最大,哈哈 [code]: #include<iostream> #include<queue> #include< ...

  3. Contest2037 - CSU Monthly 2013 Oct (problem A :Small change)

    [题解]:二进制拆分 任意一个整数都可以拆分成 2^0 + 2^1 + 2^2 + 2^3 + ....+ m [code]: #include <iostream> #include & ...

  4. Contest2037 - CSU Monthly 2013 Oct (Problem J: Scholarship)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=9 [题解]: 这题卡了一下,卡在负数的情况,负数输出 0 这题主要找到一 ...

  5. Contest2037 - CSU Monthly 2013 Oct(中南大学2013年10月月赛水题部分题解)

    Problem A: Small change 题解:http://www.cnblogs.com/crazyapple/p/3349469.html Problem B: Scoop water 题 ...

  6. CSU 1320:Scoop water(卡特兰数)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1320 题意:……是舀的时候里面必须要有1L,而不是舀完必须要有1L. 思路:才知道是卡特兰数. 这 ...

  7. 移动设备和SharePoint 2013 - 第5部分:自定义应用

    博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...

  8. 移动设备和SharePoint 2013 - 第4部分:定位

    博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...

  9. 移动设备和SharePoint 2013 - 第3部分:推送通知

    博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...

随机推荐

  1. hdu 3743 树状数组

    思路:我们只需坚守一个原则,本来就在左边的坚决不把它换到右边.也就是相邻的两个数,左边小,右边大,那么就不调换.这样对每个数,只要统计左边比它大的数的个数.可以从后面开始用树状数组统计比它小的数的个数 ...

  2. 【转】Nginx模块开发入门

    转自: http://kb.cnblogs.com/page/98352/ 结论:对Nginx模块开发入门做了一个helloworld的示例,简单易懂.也有一定的深度.值得一看. Nginx模块开发入 ...

  3. 转:nginx 从入门到精通的博文

    转:http://tengine.taobao.org/book/ Nginx开发从入门到精通   缘起 nginx由于出色的性能,在世界范围内受到了越来越多人的关注,在淘宝内部它更是被广泛的使用,众 ...

  4. display:none与visible:hidden区别

    if(list.style.display=='none'){                 list.style.display='block';             }else{       ...

  5. Linux 命令 - mkdir: 创建目录

    命令格式 mkdir [OPTION]... DIRECTORY... 命令参数 -m, --mode=MODE 设置文件的模式,类似于 chmod 命令. -p, --parents 需要时创建指定 ...

  6. ORACLE字符串分组聚合函数(字符串连接聚合函数)

    ORACLE字符串连接分组串聚函数 wmsys.wm_concat SQL代码: select grp, wmsys.wm_concat(str) grp, 'a1' str from dual un ...

  7. Java之绘制二次曲线

    前面已经介绍过绘制方法.这里不再赘述. 画一下草图来看看:灰色表示X值,红色表示Y值. 在这里要值得注意的是:当我们把它们的坐标在纸上画出来时,就会觉得“有问题”了,你看A(60,20,120,100 ...

  8. java 调用bash shell脚本阻塞的小问题的解决

    java  调用bash shell脚本阻塞的小问题的解决 背景 使用java实现的web端,web端相应用户的界面操作,使用java调用bash实现的shell脚本进行实际的操作,操作完成返回执行结 ...

  9. Objective-C 【在手动内存管理中如何写set方法】

    ------------------------------------------- set方法的内存管理 代码: #import <Foundation/Foundation.h> @ ...

  10. 记redis的一个测试

    现有020的系统架构走库存,取券通过Fetch前n条来实现买n张优惠券,但此做法在高并发时有严重的性能问题,性能问题主要体现在数据库. 为了优化此性能,系统改为redis,走队列模式,即生产者消费者. ...