zoj 3688
来源:互联网 发布:excel如何将拆分数据 编辑:程序博客网 时间:2024/06/16 20:34
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3688
组合数学题,牵涉到禁位问题,棋牌多项式,把禁位标记在棋盘上,我们要算出有i个棋子在禁位上面的方案数,这个可以用组合数学求。
#pragma comment(linker, "/STACK:1024000000,1024000000")#include <stdio.h>#include <queue>#include <map>#include <vector>#include <string>#include <cstring>#include <algorithm>#include <iostream>#include <cstdlib>#include <cctype>#include <set>#include <cmath>using namespace std;typedef long long ll;const int MOD=1e9+7;const int MAXN=2e5+10;ll f[MAXN];ll mod_pow(ll a,ll n){ ll ans=1; while(n) { if(n&1) ans=ans*a%MOD; a=a*a%MOD; n>>=1; } return ans;}int main(){ //freopen("in","r",stdin); f[0]=1; for(int i=1;i<MAXN;i++) f[i]=f[i-1]*i%MOD; int n; while(cin>>n) { ll ans=f[n]; for(int i=1;i<=n;i++) { ll v=f[2*n-i-1]*mod_pow(f[i-1],MOD-2)%MOD; v=v*mod_pow(f[2*n-2*i],MOD-2)%MOD; v=v*2*n%MOD; v=v*mod_pow(i,MOD-2)%MOD; v=v*f[n-i]%MOD; if(i%2==0) ans=(ans+v)%MOD; else ans=(ans-v+MOD)%MOD; } if(n==1) ans=0; cout<<ans<<endl; } return 0;}
0 0
- ZOJ 3688
- zoj 3688
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- 数据解析
- 自定义progressDialog~~~
- 原码, 反码, 补码 详解
- hdu 5375 Gray code(dp)
- 第10章:深入函数
- zoj 3688
- 【Android性能优化】Android-Lint:查错与代码优化利器
- maven 项目出现 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- group by的参考地址
- POJ-2187(旋转卡壳)
- final的含义
- linux内存管理之malloc
- c#学习之双冒泡运算符
- HDU 5372 Segment Game(线段树)