【CF660E】Different Subsets For All Tuples 结论题
【CF660E】Different Subsets For All Tuples
题意:对于所有长度为n,每个数为1,2...m的序列,求出每个序列的本质不同的子序列的数目之和。(多个原序列可以有相同的子序列)
$n,m\le 10^6$
题解:结论:一个子序列出现的次数只与其长度有关。
我们可以分别求出每种长度的子序列出现的总次数,显然答案为:
$\sum\limits_{i=1}^nm^i\sum\limits_{j=i}^nC_{j-1}^{i-1}(m-1)^{j-i}m^{n-j}$
(上面没有考虑k=0,一会要单独计算)
继续化简
$\sum\limits_{j=1}^nm^{n-j}\sum\limits_{i=1}^jC_{j-1}^{i-1}(m-1)^{j-i}m^i$
$\sum\limits_{j=1}^nm^{n-j+1}(2m-1)^{j-1}$
就完事了。
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- using namespace std;
- typedef long long ll;
- const ll P=1000000007;
- ll f1[1000010],f2[1000010],ans;
- int n,m;
- int main()
- {
- scanf("%d%d",&n,&m);
- int i;
- for(f1[0]=f2[0]=i=1;i<=n;i++) f1[i]=f1[i-1]*m%P,f2[i]=f2[i-1]*(m+m-1)%P;
- for(ans=f1[n],i=1;i<=n;i++) ans=(ans+f1[n-i+1]*f2[i-1])%P;
- printf("%lld",ans);
- return 0;
- }
【CF660E】Different Subsets For All Tuples 结论题的更多相关文章
- cf660E Different Subsets For All Tuples
For a sequence a of n integers between 1 and m, inclusive, denote f(a) as the number of distinct sub ...
- 【组合数学】cf660E. Different Subsets For All Tuples
比较套路的组合数学题 For a sequence a of n integers between 1 and m, inclusive, denote f(a) as the number of d ...
- [codevs5578][咸鱼]tarjan/结论题
5578 咸鱼 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 在广袤的正方形土地上有n条水平的河流和m条垂直的河流,发达的咸鱼家族在m*n个河流交叉点都 ...
- BZOJ_1367_[Baltic2004]sequence_结论题+可并堆
BZOJ_1367_[Baltic2004]sequence_结论题+可并堆 Description Input Output 一个整数R Sample Input 7 9 4 8 20 14 15 ...
- [BZOJ3609][Heoi2014]人人尽说江南好 结论题
Description 小 Z 是一个不折不扣的 ZRP(Zealot Round-game Player,回合制游戏狂热玩家), 最近他 想起了小时候在江南玩过的一个游戏. 在过去,人们是要 ...
- 【uoj#282】长度测量鸡 结论题
题目描述 给出一个长度为 $\frac{n(n+1)}2$ 的直尺,要在 $0$ 和 $\frac{n(n+1)}2$ 之间选择 $n-1$ 个刻度,使得 $1\sim \frac{n(n+1)}2$ ...
- 【uoj#175】新年的网警 结论题+Hash
题目描述 给出一张 $n$ 个点 $m$ 条边的无向连通图,每条边的边权为1.对于每个点 $i$ ,问是否存在另一个点 $j$ ,使得对于任意一个不为 $i$ 或 $j$ 的点 $k$ ,$i$ 到 ...
- 【uoj#180】[UR #12]实验室外的攻防战 结论题+树状数组
题目描述 给出两个长度为 $n$ 的排列 $A$ 和 $B$ ,如果 $A_i>A_{i+1}$ 则可以交换 $A_i$ 和 $A_{i+1}$ .问是否能将 $A$ 交换成 $B$ . 输入 ...
- Educational Codeforces Round 11 E. Different Subsets For All Tuples 动态规划
E. Different Subsets For All Tuples 题目连接: http://www.codeforces.com/contest/660/problem/E Descriptio ...
随机推荐
- css冲刺
CSS知识点及面试题 1.一般与文本相关的属性都可以继承text-/font-/line- 2.background属性1)background-repeat:repeat/repeat-x/repe ...
- 卷积的三种模式:full, same, valid
通常用外部api进行卷积的时候,会面临mode选择. 本文清晰展示三种模式的不同之处,其实这三种不同模式是对卷积核移动范围的不同限制. 设 image的大小是7x7,filter的大小是3x3 1,f ...
- 工厂模式 Factory MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- mybatis 批量添加
<insert id="addTrackBatch" parameterType="java.util.List"> INSERT INTO t_t ...
- C++ 无锁数据结构
https://www.zhihu.com/question/52629893/answer/131731126
- numpy累积
numpy累积有两类函数:np.cumxxxxx和np.ufunc.accumulate() import numpy as np a = np.arange(1, 5) print(np.cumpr ...
- Jexus 5.4.6 on CentOS 6.6
Mono 通过脚本安装 https://github.com/cjy37/linux-asp.net-installScript 版本 3.10 MongoDB 也可通过以上脚本安装 默认端口 270 ...
- Mybatis抛出:Cannot obtain primary key information from the database, generated objects may be incomplete
使用 mybatis generator 生成pojo.dao.mapper时,可能会遇到 Cannot obtain primary key information from the databas ...
- csproj文件中copy指令的使用方式
实际开发中有很多项目需要引用第三方的dll或者资源文件,且文件比较多,在运行时这些文件需要被拷贝到BIN目录. 使用VS自带的"复制到输出目录",似然方便,但是比较不零活,经过多次 ...
- Resnet BN
[深度学习]深入理解Batch Normalization批标准化 https://www.zhihu.com/topic/20084849/hot resnet(残差网络)的F(x)究竟长什么样子? ...