前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >codechef Count Relations(组合数 二项式定理)

codechef Count Relations(组合数 二项式定理)

作者头像
attack
发布2018-09-17 15:38:03
3390
发布2018-09-17 15:38:03
举报

题意

求有多少元素属于$1 \sim N$的集合满足

R1 = {(x,y):x和y属于B,x不是y的子集,y不是x的子集,x和y的交集等于空集}

R2 = {(x,y):x和y属于B,x不是y的子集,y不是x的子集,x和y的交集不等于空集}

Sol

神仙题啊Orz

我整整推了两个小时才推出来

首先写暴力

代码语言:javascript
复制
/*
*/
#include<iostream>
#include<cstdio>
#include<cstring>
//#define int long long 
#define LL int
const int MAXN = 1001;
using namespace std;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
int C[MAXN][MAXN], Po2[MAXN];
main() {
    cin >> N;
    Po2[0] = 1;
    for(int i = 1; i <= 1000; i++) Po2[i] = 2 * Po2[i - 1];
    C[0][0] = 1;
    for(int i = 1; i <= 1000; i++) {
        C[i][0] = 1;
        for(int j = 1; j <= i; j++)
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; 
    }
    int ans = 0;
    for(int i = 1; i <= N - 1; i++) {
        int now = C[N][i], sum = 0;
        for(int j = 1; j <= N - i; j++)    sum += C[N - i][j];
        //ans += now * sum;
        ans += now * (Po2[N - i] - 1);
    }
    cout << ans / 2 << " ";
    ans = 0;
    for(int i = 2; i <= N - 1; i++) {
        int res1 = C[N][i], sum1 = 0;
        for(int j = 1; j <= i - 1; j++) {
            int res2 = C[i][j], sum2 = 0;
            for(int k = 1; k <= N - i; k++) {
                sum2 += C[N - i][k];
            }
            sum1 += res2 * sum2;
        }
        ans += res1 * sum1;
    }
    cout << ans / 2;
    return 0;
}
/*
100 50 10000006
*/

然后一层一层展开即可

最后的答案为

第一问:

$$\frac{3^n + 1}{2} - 2^n$$'

第二问:

$$\frac{-3 * 3^n + 4^n - 1}{2} + 3 * 2^{n - 1}$$

代码语言:javascript
复制
/*
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define int long long 
#define LL int
const int MAXN = 1001, mod = 100000007, inv = 50000004;
using namespace std;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
int C[MAXN][MAXN], Po2[MAXN], Po3[MAXN], Po4[MAXN];
int f(int a, int p) {
    int base = 1;
    while(p) {
        if(p & 1) base = (base * a) % mod;
        a = (a * a) % mod; p >>= 1;
    }
    return base % mod;
}
main() {
    int T;
    cin >> T;
    while(T--) {
        cin >> N;
        /*Po2[0] = Po3[0] = Po4[0] = 1; 
        for(int i = 1; i <= 1000; i++) Po2[i] = 2 * Po2[i - 1], Po3[i] = 3 * Po3[i - 1], Po4[i] = 4 * Po4[i - 1];
        int ans = (Po3[N] + 1) / 2 - Po2[N];
        cout << ans << " ";
        ans = 0;
        ans = (-3 * Po3[N] + Po4[N] - 1) / 2;
        ans += Po2[N - 1] * 3;
        cout << ans;    */
        //cout << f(2, mod - 2) % mod;
        int ans = ((f(3, N) + 1) * inv - f(2, N) + mod) % mod;
        cout << ans << " ";
        ans = ((-3 * f(3, N) + mod) % mod + f(4, N) - 1 + mod) * inv + f(2, N - 1) * 3 % mod;
        ans %= mod;
        cout << ans << endl;
    }

    return 0;
}
/*
*/
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-09-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题意
  • Sol
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档