luoguP2265 路边的水沟

题目:http://www.luogu.org/problem/show?pid=2265

题解:ans=C(n+m,n)%p

        求一下逆元就行

代码;

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<iostream>
 6 #include<string>
 7 #include<set>
 8 #include<map>
 9 #include<vector>
10 #include<algorithm>
11 #include<queue>
12 #define for0(i,n) for(int i=0;i<=n;i++)
13 #define for1(i,n) for(int i=1;i<=n;i++)
14 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
15 #define for3(i,y,x) for(int i=(y);i>=(x);i--)
16 #define maxn 100000+5
17 #define mod 1000000007
18 #define ll long long 
19 using namespace std;
20 inline int read()
21 {
22     int x=0,f=1;char ch=getchar();
23     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
24     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
25     return x*f;
26 }
27 ll power(ll x,ll y)
28 {
29     ll t=1;
30     for(;y;y>>=1,x=(x*x)%mod)
31      if(y&1)t=(t*x)%mod;
32     return t;
33 }
34 int main()
35 {
36     freopen("input.txt","r",stdin);
37     freopen("output.txt","w",stdout);
38     ll n=read(),m=read();
39     ll t1=1,t2=1;
40     for1(i,n)t1=(t1*(ll)i)%mod;
41     for2(i,m+1,n+m)t2=(t2*(ll)i)%mod;
42     printf("%lld\n",t2*power(t1,mod-2)%mod);
43     return 0;
44 }
View Code

 

posted @ 2014-11-03 11:29  ZYF-ZYF  Views(193)  Comments(0Edit  收藏  举报