当前位置:网站首页>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])
边栏推荐
- Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法
- Mysql应用安装后找不到my.ini文件
- View source and switch mirrors in two ways: npm and nrm
- A complete introduction to JSqlParse of Sql parsing and conversion
- 开源汇智创未来 | 2022开放原子全球开源峰会OpenAtom openEuler分论坛圆满召开
- DVWA靶场环境搭建
- 关于出现大量close_wait状态的理解
- MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
- SQL语句中对时间字段进行区间查询
- ABC D - Distinct Trio(k元组的个数
猜你喜欢

Three oj questions on leetcode

sql statement - how to query data in another table based on the data in one table

Industry landing presents new progress | 2022 OpenAtom Global Open Source Summit OpenAtom OpenHarmony sub-forum was successfully held

ERP生产作业控制 金蝶

ERP Production Operation Control Kingdee

MySQL常见面试题汇总(建议收藏!!!)

Explanation of

MySQL开窗函数

Sql解析转换之JSqlParse完整介绍

1. 获取数据-requests.get()
随机推荐
STM32HAL库修改Hal_Delay为us级延时
ES 源码 API调用链路源码分析
XSS靶场(三)prompt to win
Blockbuster | foundation for platinum, gold, silver gave nameboards donors
sql语句-如何以一个表中的数据为条件据查询另一个表中的数据
专访 | 阿里巴巴首席技术官程立:云+开源共同形成数字世界的可信基础
centos7安装mysql5.7步骤(图解版)
mysql使用on duplicate key update批量更新数据
C Implementation of Simple Network File Copy
Three oj questions on leetcode
重磅 | 基金会为白金、黄金、白银捐赠人授牌
MySQL数据库增删改查(基础操作命令详解)
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
VScode+ESP32快速安装ESP-IDF插件
打造基于ILRuntime热更新的组件化开发
ABC D - Distinct Trio(k元组的个数
Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
MySQL to revise the root password
MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
unity2d game