当前位置:网站首页>ABC D - Distinct Trio(k元组的个数
ABC D - Distinct Trio(k元组的个数
2022-07-31 04:44:00 【__Rain】
D - Distinct Trio
题意:
给的一个序列,求出 1 ≤ i < j < k ≤ n , A i , A j , A k 1\leq i<j<k \leq n,A_i,A_j,A_k 1≤i<j<k≤n,Ai,Aj,Ak 互不相同的元组 ( i , j , k ) (i,j,k) (i,j,k) 的个数
思路:
不妨设 A i ≤ A j ≤ A k A_i \leq A_j \leq A_k Ai≤Aj≤Ak
枚举 A j A_j Aj,维护一个前缀和即可求得答案
拓展: K K K 元组
code:
n = int(input())
a = [int(x) for x in input().split()]
maxn = int(2e5 + 1)
cnt = [0 for x in range(maxn)]
vis = [0 for x in range(maxn)]
for x in a :
cnt[x] += 1
vis[x] = 1
for i in range(1, maxn) :
cnt[i] += cnt[i-1]
ans = 0
for i in range(maxn) :
if vis[i] == 0 :
continue
ans += (n - cnt[i]) * (cnt[i] - cnt[i-1]) * cnt[i-1]
print(ans)
d p dp dp 解法
code:
maxn = int(2e5 + 9)
n = int(input())
a = [int(x) for x in input().split()]
#给所有x-1存到列表a
dp = [[0 for i in range(5)] for j in range(maxn)]
#n*5的数组
cnt = [0 for i in range(maxn)]
for x in a :
cnt[x] += 1
dp[0][0] = 1
#dp[i][j]表示选了j个数,每个数都<=i,且这i个数互不相同的方法数
#dp[2e5][3]就是答案
for i in range(1, maxn) :
for j in range(5) :
if i + 1 < maxn :
dp[i][j] += dp[i - 1][j]#不选i
if i + 1 < maxn and j + 1 < 5 :
dp[i][j] += dp[i - 1][j - 1] * cnt[i]#选i
print(dp[maxn-9][3])
边栏推荐
- el-image tag doesn't work after binding click event
- Win10 CUDA CUDNN installation configuration (torch paddlepaddle)
- 高斯分布及其极大似然估计
- 三道leetcode上的oj题
- (八)Math 类、Arrays 类、System类、Biglnteger 和 BigDecimal 类、日期类
- 扫雷游戏(c语言写)
- binom二项分布,
- 【C语言】操作符详解
- Industry-university-research application to build an open source talent ecosystem | 2022 Open Atom Global Open Source Summit Education Sub-Forum was successfully held
- 【py脚本】批量二值化处理图像
猜你喜欢
SOLVED: After accidentally uninstalling pip (two ways to manually install pip)
C language confession code?
两个地址池r2负责管地址池r1负责管dhcp中继
递归实现汉诺塔问题
强化学习:从入门到入坑再到拉屎
已解决:不小心卸载pip后(手动安装pip的两种方式)
数字经济时代的开源数据库创新 | 2022开放原子全球开源峰会数据库分论坛圆满召开
MySQL based operations
Lua,ILRuntime, HybridCLR(wolong)/huatuo热更新对比分析
Unity Fighter
随机推荐
马斯克对话“虚拟版”马斯克,脑机交互技术离我们有多远
C language from entry to such as soil, the data store
Regarding the primary key id in the mysql8.0 database, when the id is inserted using replace to be 0, the actual id is automatically incremented after insertion, resulting in the solution to the repea
【C语言】操作符详解
Solved (the latest version of selenium framework element positioning error) NameError: name 'By' is not defined
(5) final, abstract class, interface, inner class
Win10 CUDA CUDNN installation configuration (torch paddlepaddle)
问题7:列表的拼接
el-image tag doesn't work after binding click event
VScode+ESP32 quickly install ESP-IDF plugin
高斯分布及其极大似然估计
Why don't you programmers make a living off your own projects?And have to work for someone else?
The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)
MySQL 8.0.30 GA
Industry-university-research application to build an open source talent ecosystem | 2022 Open Atom Global Open Source Summit Education Sub-Forum was successfully held
Fusion Cloud Native, Empowering New Milestones | 2022 Open Atom Global Open Source Summit Cloud Native Sub-Forum Successfully Held
打造基于ILRuntime热更新的组件化开发
【C语言进阶】文件操作(一)
MySQL fuzzy query can use INSTR instead of LIKE