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. C语言下的简易计算器

    #include <stdio.h> #include <math.h> int main() { double data1, data2; char op; == scanf ...

  2. 自定义android Dialog

    1.自定义Dialog: import android.app.AlertDialog; import android.app.Dialog; import android.content.Conte ...

  3. nginx实现域名重定向

    一般网站默认的访问端口为80,当多个域名指向同一个服务器IP时,可以nginx进行重定向,分别指向不同的目的地址或其他主机. 在nginx目录下的conf/vhost子目录下建两个conf文件,hos ...

  4. c++、c实现推箱子小游戏

    经过四次的修改和优化,终于将推箱子这个游戏完整的写出来了,今天就像大家分享一下这个游戏的编写. 这个游戏界面的编写总的来说不困难,主要是推动箱子的算法. (1)利用数组和windows api 即可写 ...

  5. ORACLE之PACKAGE

    刚学pl/sql编程,写了两个package.pkg_temp_fn和pkg_temp_fn2.内容涉及pl/sql基本语法,游标,存储过程(in,out),函数(有返回值). pkg_temp_fn ...

  6. 解决MS Office下载网站数据失败的问题

    最近遇到在MS Excel中建立的Web Query在创建完成后过了一段时间(或关闭文件后再次打开文件并刷新数据)出现无法刷新的问题,点击刷新时报错如下: 无法下载您要求的信息. 这是一个很不友好的报 ...

  7. 通过读取配置文件App.config来获取数据库连接字符串

    有两种方式://通过读取配置文件来获取连接字符串 第一种方式: App.config 文件的格式: <?xml version="1.0" encoding="ut ...

  8. 牢记!SQL Server数据库开发的二十一条注意点

    如果你正在负责一个基于SQL Server的项目,或者你刚刚接触SQL  Server,你都有可能要面临一些数据库性能的问题,这篇文章会为你提供一些有用的指导(其中大多数也可以用于其它的DBMS). ...

  9. sql server 判断日期当前月有多少天

    declare @tm datetime set @tm = CONVERT(datetime,'2013-3-12')declare @days intselect @days = case whe ...

  10. Android的selector,背景选择器

    原文地址 http://android.blog.51cto.com/268543/564581 首先android的selector是在drawable/xxx.xml中配置的,相关图片放在同目录下 ...