[NOI.AC] count
思路:
考虑组合数学。
当所求中没有重复的时候,方案数就是\(C_{n + 1}^{k}\)
当有重复的时候...
设相等的数字之间的距离为\(len\)
当取0个数时,方案数就是\(C_{n - 1}^{k}\)
取1个数时,方案数大概是\(2 * C_{n - 1}^{k - 1}\) ,但是如果相同的数字之间那一段没有取任何一个其他的数,那么取任意一个相同的数都是等价的,所以要减去\(C_{n - len}^{i - 1}\)
取了两个数,方案数就是\(C_{n - 1}^{k - 2}\)
考试炸了范围...
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
const int maxn = 200010;
const int mod = 1e9+7;
int n;
inline int pow_mod(int x,int y) {
int res = 1;
while(y) {
if(y & 1) res = res * x % mod;
x = x * x % mod;
y >>= 1;
}
return res % mod;
}
inline int read() {
int q=0,f=1;char ch = getchar();
while(!isdigit(ch)){
if(ch==-'-')f=-1;ch=getchar();
}
while(isdigit(ch)){
q=q*10+ch-'0';ch=getchar();
}
return q*f;
}
int fac[maxn];
int a[maxn];
int vis[maxn];
int ifac[maxn];
inline int C(int x,int y) {
if(x < y) return 0;
if(y < 0) return 0;
return fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int len;
int ans[maxn];
inline void pre () {
fac[0] = 1;
for(int i = 1;i <= n + 1; ++i) {
fac[i] = fac[i - 1] * i % mod;
}
ifac[n + 1] = pow_mod(fac[n + 1],mod - 2);
for(int i = n;i >= 0; --i) {
ifac[i] = ifac[i + 1] * (i + 1) % mod;
}
}
signed main () {
n = read();
for(int i = 1;i <= n + 1; ++i) {
a[i] = read();
if(vis[a[i]] == 0) {
vis[a[i]] = i;
}
else len = i - vis[a[i]] + 1;
}
pre();
for(int i = 1;i <= n + 1; ++i) {
int res = C(n - 1,i);
res = (res + 2 * C(n - 1,i - 1)) % mod;
res = (res - C(n - len + 1,i - 1) + mod) % mod;
res = (res + C(n - 1,i - 2)) % mod;
ans[i] = res;
}
for(int i = 1;i <= n + 1; ++i)
printf("%lld\n",ans[i]);
return 0;
}
[NOI.AC] count的更多相关文章
- [NOI.AC]COUNT(数学)
解析: 也可以将所有的可能都计算出来,后进行减法运算. 代码: #include<bits/stdc++.h> using namespace std; #define ll long l ...
- NOI.AC NOIP模拟赛 第五场 游记
NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ...
- SDOI2015 寻宝游戏 | noi.ac#460 tree
题目链接:戳我 可以知道,我们相当于是把有宝藏在的地方围了一个圈,求这个圈最小是多大. 显然按照dfs序来遍历是最小的. 那么我们就先来一遍dfs序列,并且预处理出来每个点到根的距离(这样我们就可用\ ...
- # NOI.AC省选赛 第五场T1 子集,与&最大值
NOI.AC省选赛 第五场T1 A. Mas的童年 题目链接 http://noi.ac/problem/309 思路 0x00 \(n^2\)的暴力挺简单的. ans=max(ans,xor[j-1 ...
- NOI.ac #31 MST DP、哈希
题目传送门:http://noi.ac/problem/31 一道思路好题考虑模拟$Kruskal$的加边方式,然后能够发现非最小生成树边只能在一个已经由边权更小的边连成的连通块中,而树边一定会让两个 ...
- NOI.AC NOIP模拟赛 第六场 游记
NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...
- NOI.AC NOIP模拟赛 第二场 补记
NOI.AC NOIP模拟赛 第二场 补记 palindrome 题目大意: 同[CEOI2017]Palindromic Partitions string 同[TC11326]Impossible ...
- NOI.AC NOIP模拟赛 第一场 补记
NOI.AC NOIP模拟赛 第一场 补记 candy 题目大意: 有两个超市,每个超市有\(n(n\le10^5)\)个糖,每个糖\(W\)元.每颗糖有一个愉悦度,其中,第一家商店中的第\(i\)颗 ...
- NOI.AC NOIP模拟赛 第四场 补记
NOI.AC NOIP模拟赛 第四场 补记 子图 题目大意: 一张\(n(n\le5\times10^5)\)个点,\(m(m\le5\times10^5)\)条边的无向图.删去第\(i\)条边需要\ ...
随机推荐
- 统计所有小于非负整数 n 的质数的数量,埃拉托斯特尼筛法
素数的定义:质数又称素数.一个大于1的自然数,除了1和它自身外,不能被其他自然数整除的数叫做质数. 1.暴力算法: 令i=2; 当i<n的时候,我们循环找出2-i的质数,即让i%(2~i-1), ...
- 【leetcode】973. K Closest Points to Origin
题目如下: We have a list of points on the plane. Find the Kclosest points to the origin (0, 0). (Here, ...
- 【leetcode】958. Check Completeness of a Binary Tree
题目如下: Given a binary tree, determine if it is a complete binary tree. Definition of a complete binar ...
- HTML5中的Canvas和SVG
Canvas 和 SVG 都允许我们在浏览器中创建图形,但是它们在根本上是不同的. 1 SVG SVG 是一种使用 XML 描述 2D 图形的语言. SVG 基于 XML,这意味着 SVG DOM 中 ...
- QT之QCustomPlot(一)
QDetectPlot::QDetectPlot(QWidget *parent) : QCustomPlot(parent) { QVector<), y(); // initialize w ...
- HIve分组查询返回每组的一条记录
select a.lng,a.lat from (select row_number() over ( partition by uid,grid_id) as rnum,weighted_centr ...
- Openstack组件实现原理 — Nova 体系结构
目录 目录 前文列表 Nova体系结构 虚拟机实例化流程 前文列表 Openstack组件部署 - Overview和前期环境准备 Openstack组建部署 - Environment of Con ...
- npm cnpm node yarn
1.yarn: windows 下需要下载msi文件, 2.npm,node 安装绿色版本 3.cnpm安装:npm install -g cnpm --registry=https://regist ...
- 1044 Shopping in Mars (25 分)
Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diam ...
- 卷积神经网络学习笔记(CNN)
看了很多关于卷积神经网络的论文和资料 可是我发现一个问题,就是pooling会出现一个问题 我能找到的代码里面都是用的均值子采样,如果改成最大或最小,或P范数都会在学习训练的时候遇到不知道怎么处理的问 ...