【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 ...
随机推荐
- Mac删除默认美国输入法
1.打开sudo open ~/Library/Preferences/com.apple.HIToolbox.plist 2.找到这个,然后点击删除,最后保存,然后在立马重启 3.如果要还原,直接在 ...
- C# GDI+之Graphics类 z
GDI+是GDI的后继者,它是.NET Framework为操作图形提供的应用程序编程接口,主要用在窗体上绘制各种图形图像,可以用于绘制各种数据图像.数学仿真等. Graphics类是GDI+的核心, ...
- vue项目启动时将localhost替换成指定ip地址
1.node启动vue项目时地址一般都是http://localhost:8080 2.config->index.js 中的host:‘localhost’换成host:‘你的本机ip’就可以 ...
- [转]jquery异步ajax与服务器通信过程中如何通过then方法链式传递多层数据
原文:https://www.cnblogs.com/fullstack-yang/p/6115983.html doSubmit: function(){ var dtd = $.Deferred( ...
- C#退出程序,退出任务管理器
//窗体关闭之前 this.FormClosing += (s, r) => { System.Environment.Exit(0); }; //窗体关闭 this.Closed += (s, ...
- ionic andorid apk 签名, 查看签名MD5
ionic cordova build android生成的是带签名的android-debug.apk, 这个是可以在手机上安装的, 但是换个电脑打包这个签名就不一样了, 这样就不能直接替换安装了, ...
- SQLServer Always On FCI 脑裂及可疑状态修复
FCI 双节点集群,因为晚上集群节点间的网络中断过.两个节点都觉得还有一个节点宕机,在各节点的集群管理中都看到对方已宕机. 连接到集群IP.提示 msdb 数据库有问题: watermark/2/te ...
- [转]Anatomy of a Program in Memory
Memory management is the heart of operating systems; it is crucial for both programming and system a ...
- C#通过用户名与密码访问共享目录
C#通过用户名与密码访问共享目录 using System; using System.Collections.Generic; using System.Linq; using System.Tex ...
- React Router教程
React Router教程 React项目的可用的路由库是React-Router,当然这也是官方支持的.它也分为: react-router 核心组件 react-router-dom 应用于浏览 ...