当前位置:网站首页>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])
边栏推荐
- VScode+ESP32快速安装ESP-IDF插件
- MySQL开窗函数
- CentOS7 —— yum安装mysql
- The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
- ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
- SQL语句中对时间字段进行区间查询
- ERP Production Operation Control Kingdee
- HCIP第十天_BGP路由汇总实验
- Musk talks to the "virtual version" of Musk, how far is the brain-computer interaction technology from us
- Open Source Smart Future | 2022 OpenAtom Global Open Source Summit OpenAtom openEuler sub-forum was successfully held
猜你喜欢

centos7安装mysql5.7步骤(图解版)

1. Get data - requests.get()

聚变云原生,赋能新里程 | 2022开放原子全球开源峰会云原生分论坛圆满召开

Hand in hand to realize the picture preview plug-in (3)

Blockbuster | foundation for platinum, gold, silver gave nameboards donors

城市内涝及桥洞隧道积水在线监测系统

ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法

MySQL数据库安装配置保姆级教程(以8.0.29为例)有手就行

WPF WPF 】 【 the depth resolution of the template

ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
随机推荐
Minio上传文件ssl证书不受信任
ENSP,划分VLAN、静态路由,三层交换机综合配置
Unity手机游戏性能优化系列:针对CPU端的性能调优
Puzzle Game Level Design: Reverse Method--Explaining Puzzle Game Level Design
ABC D - Distinct Trio(k元组的个数
.NET-9.乱七八糟的理论笔记(概念,思想)
Minesweeper game - C language
Lua,ILRuntime, HybridCLR(wolong)/huatuo热更新对比分析
信息系统项目管理师核心考点(五十五)配置管理员(CMO)的工作
C language confession code?
centos7安装mysql5.7步骤(图解版)
VScode+ESP32 quickly install ESP-IDF plugin
Fusion Cloud Native, Empowering New Milestones | 2022 Open Atom Global Open Source Summit Cloud Native Sub-Forum Successfully Held
重磅 | 基金会为白金、黄金、白银捐赠人授牌
mysql使用on duplicate key update批量更新数据
The 15th day of the special assault version of the sword offer
Duplicate entry 'XXX' for key 'XXX.PRIMARY' solution.
MySQL based operations
unity2d小游戏
Reinforcement learning: from entry to pit to shit