菜鸟郁闷了...# PhotoGear - 摄影器材
b*u
1 楼
原题在
https://www.hackerrank.com/challenges/triplets
There is an integer array d which does not contain more than two elements of
the same value. How many distinct ascending triples (d[i] < d[j] < d[k], i
< j < k) are present?
一开始我用了三重循环,每层用map来去重。结果小case过了,大case超时。
想了下用DP, 两个数组,第一个A[i]存储左边比 d[i]小的个数,第二个B[i]存储右边
比d[i]大的个数,这样如果不考虑重复的话就是 sum of A[i]*B[i],但是重复的情况
太难搞了
https://www.hackerrank.com/challenges/triplets
There is an integer array d which does not contain more than two elements of
the same value. How many distinct ascending triples (d[i] < d[j] < d[k], i
< j < k) are present?
一开始我用了三重循环,每层用map来去重。结果小case过了,大case超时。
想了下用DP, 两个数组,第一个A[i]存储左边比 d[i]小的个数,第二个B[i]存储右边
比d[i]大的个数,这样如果不考虑重复的话就是 sum of A[i]*B[i],但是重复的情况
太难搞了