CF #258 E

2014-07-28 17:23:23

 1 /*************************************************************************
 2     > File Name: e.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com 
 5     > Created Time: Mon 28 Jul 2014 12:43:02 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <iostream>
13 #include <algorithm>
14 using namespace std;
15 #define LL long long
16 
17 LL n,s,f[25];
18 
19 LL Quick_pow(LL x,LL y,LL p){
20     LL ans = 1;
21     while(y){
22         if(y & 1) ans = (ans * x) % p;
23         x = (x * x) % p;
24         y >>= 1;
25     }
26     return ans;
27 }
28 
29 LL Comb(LL n,LL m,LL p){
30     if(m > n)
31         return 0;
32     n %= p;
33     LL up = 1,low = 1;
34     for(LL i = 0; i < m; ++i){
35         up = up * (n - i) % p;
36         low = low * (i + 1) % p;
37     }
38     return up * Quick_pow(low,p - 2,p) % p; //乘法逆元
39 }
40 
41 void LAE(){
42     LL ans = 0;
43     const LL p = 1e9+7;
44     LL tmax = 1 << n;
45     for(LL i = 0; i < tmax; ++i){
46         LL tag = 1,sum = s;
47         for(LL j = 0; j < n; ++j){
48             if(i & (1 << j)){
49                 sum -= (f[j] + 1);
50                 tag *= -1;
51             }
52         }
53         if(sum < 0)
54             continue;
55         ans += tag * Comb(sum + n - 1,n - 1,p);
56         ans = (ans + p) % p;
57     }
58     printf("%I64d\n",ans);
59 }
60 
61 int main(){
62     scanf("%I64d%I64d",&n,&s);
63     for(LL i = 0; i < n; ++i)
64         scanf("%I64d",&f[i]);
65     LAE();
66     return 0;
67 }    

 

posted @ 2014-07-28 17:24  Naturain  阅读(246)  评论(0编辑  收藏  举报