[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\)条边需要\ ...
随机推荐
- 关于C#中Convert.ToInt32()是干什么用的
并非每个对象都可以直接转换为int.例如,以下内容将无法编译: string Maomao = "100"; int i = (int)Maomao; 因为string无法隐式转换 ...
- 【leetcode】538. Convert BST to Greater Tree
题目如下: Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the orig ...
- 屏幕尺寸,分辨率,PPI,像素之间的关系
什么是屏幕尺寸? 华为荣耀7的尺寸是5.2英寸.这个5.2英寸是手机屏幕对角线的长度. 1英寸(inch)=2.54厘米(cm) 什么是分辨率? 华为荣耀7的分辨率是1920PX*1080PX.像素是 ...
- phpstorm使用说明
1.phpstorm软件可以直接断点调试php代码.具体配置方法参考 http://blog.csdn.net/qq4551091/article/details/55258664 就可以了,不过只要 ...
- centos 安装 ImageMagick
ImageMagick很好用,shell下可以批量对图片做处理,很赞!~ 编译安装 wget http://www.imagemagick.org/download/ImageMagick.tar.g ...
- [HNOI2011]卡农 题解
题目描述 众所周知卡农是一种复调音乐的写作技法,小余在听卡农音乐时灵感大发,发明了一种新的音乐谱写规则.他将声音分成 n 个音阶,并将音乐分成若干个片段.音乐的每个片段都是由 1 到 n 个音阶构成的 ...
- [NOI2016]区间 题解(决策单调性+线段树优化)
4653: [Noi2016]区间 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 1593 Solved: 869[Submit][Status][ ...
- EF 关键字
https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/query-keywords 子句 说明 from ...
- Ubuntu 没有 无线网 RTL8821ce 8111 8186
1.将ubuntu的linux内核版本更改到4.14(其他版本不兼容这个无线网卡的驱动) 1.1 找到内核版本 #到 Ubuntu网站http://kernel.ubuntu.com/~kernel- ...
- 剑指offer——47把数组排成最小的数
题目描述 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323. 题解: ...