zoukankan      html  css  js  c++  java
  • Atcoder arc077 D

    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
    ", ans);
    		}
    	}
        return 0;
    }
    
  • 相关阅读:
    ExtJS4学习笔记二--表单控件相关
    Js中replace()的用法
    浅析轮询(Polling)和推送(LongPolling)服务
    ExtJS4学习笔记五--面板使用
    ExtJS4学习笔记四--图片上传
    spring MVC
    ExtJS4学习笔记三--远程访问数据源示例
    Struts 2
    ExtJs4学习笔记一--基础知识
    URL编码规则
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/7189653.html
Copyright © 2011-2022 走看看