Link

题意:给出n个数,其中有一个数会出现两次,其余数只出现一次,问不同长度且不同的子串的数量。取模1e9+7

思路:组合求出所有情况,减去重复情况,注意用逆元即可

/** @Date    : 2017-07-06 09:56:44
* @FileName: atcoder077 D 组合.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;
const LL mod = 1e9 + 7; LL a[N];
LL inv[N];
LL fa[N];
LL n; void init()
{
fa[0] = fa[1] = 1;
inv[1] = 1;
for(LL i = 2; i < N; i++)
{
fa[i] = fa[i-1] * i % mod;
inv[i] = (mod - mod / i) * inv[mod % i] % mod;
}
inv[0] = 1;
for(int i = 1; i < N; i++)
(inv[i] *= inv[i - 1]) %= mod;
} LL C(LL n, LL k)
{
LL ans = 0;
if(k > n)
return ans;
ans = ((fa[n] * inv[k] % mod) * inv[n - k]) % mod;
return ans;
}
int main()
{
init();
while(cin >> n)
{
map<LL, int>q;
LL p = 0;
for(int i = 1; i <= n + 1; i++)
{
scanf("%lld", a + i);
if(!q[a[i]])
q[a[i]] = i;
else
p = i;
}
for(int i = 0; i <= n; i++)
{
LL ans = 0;
ans = (ans + C(n + 1, i + 1)) % mod;
ans = (ans - C(n - p + q[a[p]], i)) % mod;
while(ans < 0)
ans += mod;
printf("%lld\n", ans);
}
}
return 0;
}

Atcoder arc077 D - 11 组合的更多相关文章

  1. (转)Spring4.2.5+Hibernate4.3.11组合开发

    http://blog.csdn.net/yerenyuan_pku/article/details/52887573 搭建和配置Spring与Hibernate整合的环境 今天我们来学习Spring ...

  2. “几何画板+MathType”双11组合特价,优惠多多

    工欲善其事,必先利其器!几何画板和MathType作为数学老师必备工具,在数学教学中起着非常重要的作用.为回馈老师们做出的伟大贡献,在双11狂欢节期间,MathType和几何画板迎来史上第一次组合特惠 ...

  3. 设计模式C++描述----11.组合(Composite)模式

    一. 举例 这个例子是书上的,假设有一个公司的组结结构如下: 它的结构很像一棵树,其中人力资源部和财务部是没有子结点的,具体公司才有子结点. 而且最关健的是,它的每一层结构很相似. 代码实现如下: / ...

  4. AtCoder AGC036C GP 2 (组合计数)

    题目链接 https://atcoder.jp/contests/agc036/tasks/agc036_c 题解 终于有时间补agc036的题了. 这题其实不难的来着--我太菜了考场上没想出来 首先 ...

  5. Head First 设计模式 —— 11. 组合 (Composite) 模式

    思考题 我们不仅仅要支持多个菜单,升值还要支持菜单中的菜单.你如何处理这个新的设计需求? P355 [提示]在我们的新设计中,真正需要以下三点: P354 我们需要某种属性结构,可以容纳菜单.子菜单和 ...

  6. AtCoder Grand Contest 11~17 做题小记

    原文链接https://www.cnblogs.com/zhouzhendong/p/AtCoder-Grand-Contest-from-11-to-20.html UPD(2018-11-16): ...

  7. (转)Spring4.2.5+Hibernate4.3.11+Struts1.3.8集成方案一

    http://blog.csdn.net/yerenyuan_pku/article/details/52888808 前面我们已经集成了Spring4.2.5+Hibernate4.3.11这两个框 ...

  8. AtCoder Regular Contest 119 C - ARC Wrecker 2(同余定理+思维)

    Problem Statement There are NN buildings along the AtCoder Street, numbered 11 through NN from west ...

  9. POJ 1017 Packets

    题意:有一些1×1, 2×2, 3×3, 4×4, 5×5, 6×6的货物,每个货物高度为h,把货物打包,每个包裹里可以装6×6×h,问最少几个包裹. 解法:6×6的直接放进去,5×5的空隙可以用1× ...

随机推荐

  1. “我爱淘”第二冲刺阶段Scrum站立会议7

    完成任务: 完成学院分类的点击查看书籍功能,可以点击书的条目查看书的详细信息.将登陆界面以及注册发布界面完善了一下修复一些bug. 计划任务: 将书的详细信息进行完善,并且可以点击收藏以及已预订等功能 ...

  2. 代码查重工具sim

    在瞎搜东西的时候,发现了一个大牛的博客 看起来很厉害的样子...做了一个LaTeX的语法检查并给出适当的提示,上wiki上一查发现他竟然是CVS第一个版本的发明者和开发者...Dick grune这是 ...

  3. Alpha 冲刺7

    队名:日不落战队 安琪(队长) 今天完成的任务 完善回收站. 学习okhttp. 明天的计划 继续研究okhttp. 尝试登录的数据对接. 还剩下的任务 个人信息对接. 遇到的困难 今天白天焊接,晚上 ...

  4. lintcode-445-余弦相似度

    445-余弦相似度 Cosine similarity is a measure of similarity between two vectors of an inner product space ...

  5. 使用docker国内镜像解决方案

    1:蜂巢镜像 https://c.163yun.com/hub#/m/library/ 例如: docker pull hub.c.163.com/library/nginx:1.8 再次执行dock ...

  6. PAT 甲级 1046 Shortest Distance

    https://pintia.cn/problem-sets/994805342720868352/problems/994805435700199424 The task is really sim ...

  7. tomcat下部署了多个项目启动报错java web error:Choose unique values for the 'webAppRootKey' context-param in your web.xml files

    应该是tomcat下部署了多个项目且都使用log4j. <!--如果不定义webAppRootKey参数,那么webAppRootKey就是缺省的"webapp.root". ...

  8. ios 中不new Date 的格式 不支持年月日 以‘-’ 分割的格式

    new Date("2018-1-5") 在 ios 中显示 invalid date - 换做 / 则可以顺利显示 new Date("2018/1/5")

  9. Using the command line to manage files on HDFS--转载

    原文地址:http://zh.hortonworks.com/hadoop-tutorial/using-commandline-manage-files-hdfs/ In this tutorial ...

  10. 【uoj#174】新年的破栈 贪心

    题目描述 给你一个长度为 $n$ 的序列和一个空的双端队列,每次进行3种操作种的一种: 1.将序列中编号最小的数加入到双端队列的队尾:2.从双端队列的队尾取出一个数:3.从双端队列的队头取出一个数. ...