3 条题解
-
1
#include <stdio.h> typedef long long ll; const int N = 1e7, mod = 1e9 + 7; int cnt[N + 7]; ll fac[N + 7], inv[N + 7]; inline void init(int n){ fac[0] = 1; for (register int i = 1; i <= n; i++){ fac[i] = fac[i - 1] * i % mod; } inv[0] = inv[1] = 1; for (register int i = 2; i <= n; i++){ inv[i] = mod - (mod / i) * inv[mod % i] % mod; } } inline int read(){ int ans = 0; char ch = getchar(); while (ch < '0' || ch > '9'){ ch = getchar(); } while (ch >= '0' && ch <= '9'){ ans = ans * 10 + (ch ^ 48); ch = getchar(); } return ans; } int main(){ int n = read(), ni = n + 1; ll ans = 0; init(ni); for (register int i = 1; i <= n; i++){ int a = read(); cnt[a]++; } for (register int i = 1; i <= N; i++){ if (cnt[i]>0) ans = (ans + inv[cnt[i] + 1]) % mod; } printf("%lld", ans*fac[ni]%mod); return 0; }
信息
- ID
- 275
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 5
- 标签
- 递交数
- 73
- 已通过
- 30
- 上传者