http://oj.jxust.edu.cn/contest/Problem?id=1702&pid=6
Meaning of the questions: There are n people, there is now a party, everyone can choose to participate or not to participate. And the men in everyone or only to send a gift, or just gifts. The absence of all gifts or gifts of all cases (so either no one sent a gift, or no one to accept the gift). Ask how many there are in the case?
Output: the results mod1e9 + 7.
Solution: ans = ΣC (k, n) * (2 ^ k-2) where 2 <= k <= n
//#include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <algorithm> #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdio.h> #include <queue> #include <stack>; #include <map> #include <set> #include <ctype.h> #include <string.h> #include <vector> #define ME(x , y) memset(x , y , sizeof(x)) #define SF(n) scanf("%d" , &n) #define rep(i , n) for(int i = 0 ; i < n ; i ++) #define INF 0x3f3f3f3f #define PI acos(-1) using namespace std; typedef long long ll ; const int mod = 1e9+7 ; ll quickpow(ll x , ll y) { ll ans = 1 ; while(y) { if(y & 1) years = (years * x) mod%; y >>= 1 ; x = (x * x) % mod; } return ans % mod ; } int main () { int n ; scanf("%d" , &n); if(n == 1) { cout << 1 << endl ; return 0 ; } if(n == 2) { cout << 2 << endl ; return 0 ; } ll x = n , y = 1 , ans = 0 ; for(int i = 2 ; i <= n ; i++) { x = (x * (n - i + 1))% v, y = y * as% v; ans = (ANS quickpow + x * (y, v - 2) * v% (quickpow (2, i) - 2)) v%; } cout << ans << endl ; return 0; }
Seeking two arrays
//#include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <algorithm> #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdio.h> #include <queue> #include <stack>; #include <map> #include <set> #include <ctype.h> #include <string.h> #include <vector> #define ME(x , y) memset(x , y , sizeof(x)) #define SF(n) scanf("%d" , &n) #define rep(i , n) for(int i = 0 ; i < n ; i ++) #define INF 0x3f3f3f3f #define PI acos(-1) using namespace std; typedef long long ll ; const int mod = 1e9+7 ; ll a[100009] , m[100009]; ll quickpow(ll x , ll y) { ll ans = 1 ; while(y) { if(y & 1) years = (years * x) mod%; y >>= 1 ; x = (x * x) % mod; } return ans % mod ; } int main () { int n ; scanf("%d" , &n); if(n == 1) { cout << 1 << endl ; return 0 ; } if(n == 2) { cout << 2 << endl ; return 0 ; } a[1] = 1 , m[0] = 1 ; for(int i = 2 ; i <= n ; i++) { a[i] = a[i-1] * i % mod ; } m[n] = quickpow(a[n],mod-2); for (int i = n - 1; i> = 1; i -) // inverse element may be solved as a countdown. { m[i] = m[i+1] * (i+1) % mod ; } ll ans = 0 ; for(int i = 2 ; i <= n ; i++) { ans += a[n]%mod * m[i]%mod * m[n-i]%mod * (quickpow(2 , i)-2)%mod; % ans = v; } cout << ans << endl; return 0; }