题意:

给一集合 $S = \{ 1,2, ... , n \} $,取两个S的子集 A和B,使得A不是B的子集,且B不是A的子集。

解法:

1.牛顿展开

我们采用容斥,显然有

$$ans(n) = (2^n - 1)^2 - 2* \sum_{k=1}^n{C_n^k * (2^k - 2)} - (2^n-1)$$

$$ans(n) = (2^n - 1)(2^n-2) - 2*(\sum_{k=1}^n{C_n^k *2^k} - 2*\sum_{k=1}^n{C_n^k})$$

$$ans(n) = 4^n - 2*3^n + 2^n$$

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <complex>
#include <cmath>
#include <ctime> using namespace std; #define N 1000010
#define LL long long
#define P 1000000007LL using namespace std; LL power3[N],power2[N]; int main()
{
power3[]=;
power2[]=;
for(int i=;i<N;i++)
{
power3[i] = power3[i-] * 3LL % P;
power2[i] = power2[i-] * 2LL % P;
}
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
LL ans = power2[n]*(power2[n]+1LL)%P;
ans = (ans+P-2LL*power3[n]%P)%P;
printf("%I64d\n",ans);
}
return ;
}

2.生成函数(待补)

可以构造出

Count Subsets的更多相关文章

  1. LeetCode----Array

    Remove Duplicates from Sorted Array 思路:两个指针,头指针在0,尾指针从1开始寻找,找到第一个不等于头指针值的数,覆盖掉头指针后面那个数,然后尾指针往后移. pub ...

  2. 【子集或者DFS】部分和问题

    题目: 给定整数序列a1,a2,...,an,判断是否可以从中选出若干数,使它们的和恰好为k.1≤n≤20   -108≤ai≤108   -108≤k≤108 输入: n=4 a={1,2,4,7} ...

  3. nodejs api 中文文档

    文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...

  4. 【leetcode】Subsets II (middle) ☆

    Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...

  5. 90. Subsets II(中等,编写代码有难度)

    Given a collection of integers that might contain duplicates, nums, return all possible subsets. Not ...

  6. [Swift]LeetCode78. 子集 | Subsets

    Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solut ...

  7. [Swift]LeetCode90. 子集 II | Subsets II

    Given a collection of integers that might contain duplicates, nums, return all possible subsets (the ...

  8. [Swift]LeetCode698. 划分为k个相等的子集 | Partition to K Equal Sum Subsets

    Given an array of integers nums and a positive integer k, find whether it's possible to divide this ...

  9. 78. Subsets(M) & 90. Subsets II(M) & 131. Palindrome Partitioning

    78. Subsets Given a set of distinct integers, nums, return all possible subsets. Note: The solution ...

随机推荐

  1. redis 3.0.1 在CentOS上的安装

    一.下载 wget http://download.redis.io/releases/redis-3.0.1.tar.gz 二.解压 tar xzf redis-3.0.1.tar.gz 三.进入 ...

  2. python(11)- 文件处理

    文件操作 1.1 对文件操作流程 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 现有文件如下: 昨夜寒蛩不住鸣. 惊回千里梦,已三更. 起来独自绕阶行. 人悄悄,帘外月胧明 ...

  3. mysql大数据量下修改表结构的方法

    http://www.blogjava.net/anchor110/articles/361152.html

  4. HTML5、CSS3等新特性:

    HTML5:1/绘画 canvas 元素;2/用于媒介回放的 video 和 audio 元素;3/本地离线存储 localStorage 长期存储数据,浏览器关闭后数据不丢失;4/sessionSt ...

  5. 为什么应使用 Node.js

    为什么应使用 Node.js JavaScript 高涨的人气带来了很多变化,以至于如今使用其进行网络开发的形式也变得截然不同了.就如同在浏览器中一样,现在我们也可以在服务器上运行 JavaScrip ...

  6. man screen

    http://www.gnu.org/software/screen/manual/screen.html Screen User's Manual Next: Overview, Previous: ...

  7. laravel 配置了自己的域名以后, localhost 无法访问 404 not found 的解决方法

    这是后盾网视频教程的方法,应该是配置虚拟主机,此方法要改动,apache服务器里的conf文件夹里的httpd.conf文件 和conf/extral里面的httpd-vhost文件 具体改动为,co ...

  8. Laravel建站05--缓存、时间日期处理包

    缓存 Laravel 给多种缓存系统提供丰富而统一的 API,缓存配置信息位于 config/cache.php,在这个文件中你可以为你的应用程序指定默认的缓存驱动,Laravel 支持当前流行的缓存 ...

  9. 文件另存为——Autocad.doc.SaveAs

    一.前言 使用pyautocad编辑好cad图纸后,往往涉及到一个保存的问题,但是官方文档并未提及,所以只能自己来了,测试了好久,终于是找到了保存的命令和参数说明. 二.方法介绍 Autocad.do ...

  10. python--多种程序分析(2)

    1.文件操作有哪些模式?请简述各模式的作用 r模式只读  w模式只写 a模式只添加   r+可读可写  w+可写可读  a+可读可添加   rb  二进制只读  wb 二进制只写   ab 二进制添加 ...