Contest2037 - CSU Monthly 2013 Oct (problem B :Scoop water)
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)的更多相关文章
- 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 ...
- Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)
[题解]: 最短路径问题,保证距离最短的同时,学妹权值最大,哈哈 [code]: #include<iostream> #include<queue> #include< ...
- Contest2037 - CSU Monthly 2013 Oct (problem A :Small change)
[题解]:二进制拆分 任意一个整数都可以拆分成 2^0 + 2^1 + 2^2 + 2^3 + ....+ m [code]: #include <iostream> #include & ...
- Contest2037 - CSU Monthly 2013 Oct (Problem J: Scholarship)
http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=9 [题解]: 这题卡了一下,卡在负数的情况,负数输出 0 这题主要找到一 ...
- Contest2037 - CSU Monthly 2013 Oct(中南大学2013年10月月赛水题部分题解)
Problem A: Small change 题解:http://www.cnblogs.com/crazyapple/p/3349469.html Problem B: Scoop water 题 ...
- CSU 1320:Scoop water(卡特兰数)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1320 题意:……是舀的时候里面必须要有1L,而不是舀完必须要有1L. 思路:才知道是卡特兰数. 这 ...
- 移动设备和SharePoint 2013 - 第5部分:自定义应用
博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...
- 移动设备和SharePoint 2013 - 第4部分:定位
博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...
- 移动设备和SharePoint 2013 - 第3部分:推送通知
博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...
随机推荐
- Android中IntentService的原理及使用
在Android开发中,我们或许会碰到这么一种业务需求,一项任务分成几个子任务,子任务按顺序先后执行,子任务全部执行完后,这项任务才算成功.那么,利用几个子线程顺序执行是可以达到这个目的的,但是每个线 ...
- Codevs 2307[SDOI2009]HH的项链
同题: Codevs 2307 HH的项链 BZOJ 1878 HH的项链 洛谷 1972 HH的项链 2009年省队选拔赛山东 时间限制: 1 s 空间限 ...
- Servlet & JSP - HttpSession
关于 Session 的内容,参考 HTTP - Session 机制 创建和检索 HttpSession 通过 HttpServletRequest.getSession 方法可以获取 HttpSe ...
- 每天一道LeetCode--172. Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- Dalvik字节码的类型,方法与字段表示方法
Dalvik字节码有着自己的类型,方法与字段表示方法,这些方法与Dalvik虚拟机指令集一起组成了一条条的Dalvik汇编代码. 1.类型 Dalvik字节码只有两种类型,基本类型与引用类型.Dalv ...
- Microsoft.Practices.EnterpriseLibrary.Logging的使用
翻译 原文地址:http://www.devx.com/dotnet/Article/36184/0/page/1 原文作者:Thiru Thangarathinam (好强大的名字) 翻译: fl ...
- xcode-重新打开欢迎界面
嫌不够逼格关掉 关掉又后悔= = 重新打开方式为: command+shift+1 然后把左下勾上就可以每次都打开了 一个字,折腾
- C 再识数组指针 指针数组的概念
参考出处: http://www.cnblogs.com/mq0036/p/3382732.html http://www.cnblogs.com/hongcha717/archive/2010/10 ...
- 如何在Android SDK 下查看应用程序输出日志的方法
该文章源于安卓教程网(http://android.662p.com),转载时要注明文章的来自和地址,感谢你的支持. 在Android程序中可以使用 android.util.Log 类来 ...
- sed- 文本流编辑器
sed [选项] [参数] -n 被操作行打印输出 ...