D - 11(逆元好题)

简介: D - 11(逆元好题)
#include<bits/stdc++.h>
#define debug1(a) cout<<#a<<'='<< a << endl;
#define debug2(a,b) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<"  "<<#d<<" = "<<d<<endl;
#define debug5(a,b,c,d,e) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<"  "<<#d<<" = "<<d<<"  "<<#e<<" = "<<e<<endl;
#define debug0(x) cout << "debug0: " << x << endl
#define fr(t, i, n)for (long long i = t; i < n; i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fi first
#define se second
#define int long long
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
//#pragma GCC optimize(3,"Ofast","inline")
//#pragma GCC optimize(2)
/*
如果无视不同的要求,那么答案就是 C(n+1,k)。
什么时候会有重复的呢?
只可能是 a 中那两个相同的数字,恰好选了其中一个导致的。
设 a 中那两个相同数字的下标分别为 p 和 q(下标从 0 开始),
手玩一下可以发现,如果剩余的 k-1 个数是在 p 左边或 q 右边中选的,就会导致重复。
这一共有 m = p + (n-q) 个数���
因此答案为 C(n+1,k) - C(m,k-1)。
计算组合数需要逆元。
逆元组合数,无时无刻都要注意逆元的定义
*/
const int N = 100010,mod = 1e9 + 7;
int fact[N],ifact[N];
int a[N];
int to[N];
LL qmi(int a,int b,int p){                                          //快速幂
    LL res = 1;
    while(b){
        if(b&1)res = (LL)res * a % p;
        b = b >> 1;
        a = (LL)a * a % p;
    }
    return res;
}
LL C(int a,int b)
{
    return (LL)fact[a] * ifact[b] % mod * ifact[a - b] % mod;
}
void solve() 
{
    fact[0] = ifact[0] = 1;
    
    for(int i = 1;i < N;i++){
        fact[i] = (LL)fact[i - 1] * i % mod;                        //阶乘
        ifact[i] = (LL)ifact[i - 1] * qmi(i, mod - 2, mod) % mod;   //阶乘对于mod的乘法逆元
        //cout << fact[i] << " " << ifact[i] << endl;
    }
    int n;cin >> n;
    for(int i = 1;i <= n+1;i++)cin >> a[i];
    
    for(int i = 1;i <= n+1;i++)
    {
        if(!to[a[i]])to[a[i]] = i;
        else 
        {
            int l,r;
            l = to[a[i]],r=i;
            int m = l-1 + n - r + 1;
            
    
            //(LL)fact[a] * ifact[b] % mod * ifact[a - b] % mod
            for(int i = 1;i <= n+1;i ++)
            {
                if(m >= i-1)cout << (C(n+1,i) - C(m,i-1) + mod) % mod << endl;
                else cout << (C(n+1,i) % mod) << endl;
            }
            break;
        }
    }
}
signed main()
{
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    */
    int T = 1;//cin >> T;
    while(T--){
        solve();
    }
    return 0;
}


相关文章
|
4月前
|
存储 人工智能 缓存
DeepSeek Harness 全景可观测实践
日志能记下发生了什么,却说不清时间和 Token 花在哪。基于开源 LoongSuite,DeepSeek Harness 有了两条 OpenTelemetry 路线:插件两分钟直发 OTLP,Pilot 统一观测多个 Agent。
|
人工智能 JavaScript 开发工具
极速上手!Claude Code 原生支持 Windows 免WSL安装教程
Claude Code 现已支持 Windows 原生运行,无需 WSL 配置。本文提供详细安装教程,涵盖 Node.js 环境验证、Git 安装及 Claude Code 配置步骤,助你快速上手这一强大 AI 编程工具。
13922 13
|
开发者 异构计算
现在,一行命令使用Ollama运行任意魔搭GGUF模型
为了让开发者更方便地把这些模型用起来,社区最近支持了Ollama框架和ModelScope平台的链接,通过简单的 ollama run命令,就能直接加载运行ModelScope模型库上的GGUF模型。
|
9天前
|
域名解析 人工智能 Linux
|
19天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17344 63
|
17天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
3天前
|
人工智能 安全 网络安全
|
6天前
|
云安全 数据采集 人工智能
|
7天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1332 3
|
14天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2408 7

热门文章

最新文章