当前位置:网站首页>ABC D - Distinct Trio (Number of k-tuples
ABC D - Distinct Trio (Number of k-tuples
2022-07-31 04:55:00 【__Rain】
D - Distinct Trio
题意:
given a sequence,求出 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 Tuples that are distinct from each other ( 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,Maintain a prefix sum to get the answer
拓展: 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,且这iThe number of methods differs from each other
#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])
边栏推荐
- 【wpf】wpf中的那些模板之深度解析
- DVWA shooting range environment construction
- View source and switch mirrors in two ways: npm and nrm
- 【debug锦集】Expected input batch_size (1) to match target batch_size (0)
- A complete introduction to JSqlParse of Sql parsing and conversion
- MySQL常见面试题汇总(建议收藏!!!)
- ERP生产作业控制 金蝶
- Duplicate entry 'XXX' for key 'XXX.PRIMARY' solution.
- VScode+ESP32 quickly install ESP-IDF plugin
- MySQL based operations
猜你喜欢
ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)Solution
sql语句-如何以一个表中的数据为条件据查询另一个表中的数据
开源汇智创未来 | 2022开放原子全球开源峰会OpenAtom openEuler分论坛圆满召开
【线性神经网络】softmax回归
MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
Minesweeper game (written in c language)
Two address pools r2 are responsible for managing the address pool r1 is responsible for managing dhcp relays
Heavyweight | The Open Atomic School Source Line activity was officially launched
微信小程序使用云函数更新和添加云数据库嵌套数组元素
[Linear Neural Network] softmax regression
随机推荐
Sql解析转换之JSqlParse完整介绍
C language confession code?
MySQL数据库增删改查(基础操作命令详解)
EasyExcel的简单读取操作
ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
Heavyweight | The Open Atomic School Source Line activity was officially launched
Minesweeper game - C language
城市内涝及桥洞隧道积水在线监测系统
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法
[C language] Detailed explanation of operators
MySQL database must add, delete, search and modify operations (CRUD)
MySQL database installation (detailed)
The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
npm、nrm两种方式查看源和切换镜像
HCIP Day 10_BGP Route Summary Experiment
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
prompt.ml/15中<svg>标签使用解释
剑指offer专项突击版第15天
MySQL数据库备份
两个地址池r2负责管地址池r1负责管dhcp中继