---
id: 493
title: "P3773:「CTSC2017」吉夫特题解"
slug: p3773-ctsc2017-gift
lang: zh
date: 2019-01-08T22:25:14
date_gmt: 2019-01-08T14:25:14
modified: 2023-11-11T14:50:49
status: publish
password_protected: false
category: { name: Olympiad in Informatics, slug: oi }
tags: [OI, 数学, 组合数]
original_url: https://kalorona.com/oi/p3773ctsc2017吉夫特题解/
archived: 2026-11-27
editor: classic
media: []
archive_notes:
  - "Body headings were <h1> in the original; demoted to level 2 so the page title is the only h1."
  - "The attachment gift-extension-magento.png was only the theme's featured image (post thumbnail), not part of the post body, so it was not copied."
comments: []
---

## 神仙思路

有一个“显然”的定理：如果满足$n\&k==k$，那么$C^k_n$为奇数。具体感性证明：[litble 的证明](https://www.luogu.org/blog/litble-blog/solution-p3773)。所以，直接上代码。

## 代码

```cpp
// P3773.cpp
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAX_N = 233393, mod = 1000000007;
int n, arr[MAX_N], bucket[MAX_N], f[MAX_N], ans;
int getMod(int num) { return num >= mod ? num - mod : num; }
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &arr[i]), bucket[arr[i]] = i;
    for (int i = n; i >= 1; i--)
    {
        f[i] = 1;
        for (int j = (arr[i] & (arr[i] - 1)); j; j = arr[i] & (j - 1))
            if (bucket[j] > i)
                f[i] = getMod(f[i] + f[bucket[j]]);
        ans = getMod(ans + f[i]);
    }
    ans = (ans - n + mod) % mod;
    printf("%d", ans);
    return 0;
}
```
