当前位置:网站首页>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])
边栏推荐
- (5) final, abstract class, interface, inner class
- 递归实现汉诺塔问题
- MySQL fuzzy query can use INSTR instead of LIKE
- qlib自动化quant
- 扫雷小游戏——C语言
- Unity打灵狐者
- Create componentized development based on ILRuntime hot update
- [R language] [3] apply, tapply, lapply, sapply, mapply and par function related parameters
- Reinforcement learning: from entry to pit to shit
- MySQL数据库增删改查(基础操作命令详解)
猜你喜欢

From scratch, a mirror to the end, a pure system builds a grasscutter (Grasscutter)

The input input box displays the precision of two decimal places

ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
![[C language] General method of base conversion](/img/28/954af5f47a79ff02d3cc0792ac8586.jpg)
[C language] General method of base conversion

(4) Recursion, variable parameters, access modifiers, understanding main method, code block

VScode+ESP32 quickly install ESP-IDF plugin

益智类游戏关卡设计:逆推法--巧解益智类游戏关卡设计

The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations

递归实现汉诺塔问题

C language from entry to such as soil, the data store
随机推荐
Two address pools r2 are responsible for managing the address pool r1 is responsible for managing dhcp relays
(5) final, abstract class, interface, inner class
Notes on the establishment of the company's official website (6): The public security record of the domain name is carried out and the record number is displayed at the bottom of the web page
BUG destroyer!!Practical debugging skills are super comprehensive
XSS靶场(三)prompt to win
Can't load /home/Iot/.rnd into RNG
PWN ROP
[R language] [3] apply, tapply, lapply, sapply, mapply and par function related parameters
【wpf】wpf中的那些模板之深度解析
Unity shader forge和自带的shader graph,有哪些优缺点?
exsl文件预览,word文件预览网页方法
Unity Fighter
ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
The idea project obviously has dependencies, but the file is not displayed, Cannot resolve symbol 'XXX'
HCIP Day 10_BGP Route Summary Experiment
【C语言】操作符详解
MATLAB/Simulink&&STM32CubeMX工具链完成基于模型的设计开发(MBD)(三)
参考代码系列_1.各种语言的Hello World
(六)枚举、注解
MATLAB/Simulink & & STM32CubeMX tool chain completes model-based design development (MBD) (three)