Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 87c95ff

Browse files
aQuaaQua
aQua
authored and
aQua
committed
673 wrong answer
1 parent 0635a77 commit 87c95ff

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed
Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
package Problem0673
22

33
func findNumberOfLIS(a []int) int {
4-
size := len(a)
5-
rec := make([]int, 0, size)
4+
res := 0
5+
maxLen := 0
66

7-
for _, n := range a {
8-
isUsed := false
9-
for i := range rec {
10-
if rec[i] < n {
11-
rec[i] = n
12-
isUsed = true
13-
}
14-
}
15-
if !isUsed {
16-
rec = append(rec, n)
17-
}
7+
dfs(a, -1<<63, 0, 0, &maxLen, &res)
8+
9+
return res
10+
}
11+
12+
func dfs(a []int, Min, index, length int, maxLen, res *int) {
13+
if *maxLen < length {
14+
*maxLen = length
15+
*res = 1
16+
} else if *maxLen == length && length > 0 {
17+
*res++
1818
}
1919

20-
return len(rec)
20+
Max := 1<<63 - 1
21+
22+
for i := index; i < len(a); i++ {
23+
if Min < a[i] && a[i] <= Max {
24+
Max = a[i]
25+
dfs(a, a[i], i+1, length+1, maxLen, res)
26+
}
27+
}
2128
}

Algorithms/0673.number-of-longest-increasing-subsequence/number-of-longest-increasing-subsequence_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ var tcs = []struct {
1313
ans int
1414
}{
1515

16+
{
17+
[]int{-51352, 15205, -65427, -83043, 76659, -8024, -85277, -44152, 36446, 93694, 50743, 12892, 27985, 32150, -63844, 55946, -4000, 14123, 63541, 74544, -42255, 97608, 76290, 27429, 44628, 15894, 87961, -18456, 7487, 96033, 56941, 10910, -1177, 8875, 30191, 82607, -43724, 38113, 94726, 29250, 74589, 77271, -19031, -89367, 59834, -92444, 18138, -10681, -48922, 49634, 36196, 55360, 35096, -65044, -36847, 69609, 96398, 63949, 51367, -4949, 69677, -55449, -81826, 59265, 19403, -85698, 76146, 19048, -50975, 88533, 89822, -93839, 29632, -52868, -35704, -13993, 97623, 47644, 76941, 41852, 12972, -738, -97741, -8150, 28516, 33046, 63634, 15042, 90687, -25488, 64622, -46530, -56385, 13007, 38522, 42333, -55614, 69245, -88282, 98610, -82087, -87454, 95891, -22632, 79349, 48546, -31268, -6520, 4055, 37809, 75194, -59844, 99284, -6329, 11295, 19556, -55531, 66976, 92077, 97764, 45497, -17626, 74660, -57832, 83829, 46739, 35576, 38315, 4126, 23089, 64671, 12780, -96665, -47985, 83770, 46694, 91307, 94410, 8820, -83994, -21045, 70822, 73097, -7177, 69717, 84186, -57132, -76130, 8738, 35818, -91206, -72574, 93176, -16995, -7734, 69773, 231, 47933, -2643, -34384, 80255, -76597, 24155, 41216, -44050, -82503, 24778, 21380, -56159, -54978, 22079, 1605, -28798, 85924, 45973, 52543, 45626, -85452, -32778, 75165, 42902, 22760, 17184, 96065, 88094, 81662, 20794, -13057, 33818, 62533, 9566, -52279, 20672, -43700, -67264, -59657, 23083, 64271, 7131, 30780, 66781, 40609, -18707, 20102, 77835, -40754, -24429, 85711, 59703, 91752, -76222, 55709, 19870, 96364, 67733, 24778, 1359, 14301, 14847, -55484, 89580, -79042, 460, -42022, 3700, 48167, -90309, 39300, -85033, -1761, 33443, -46567, 64901, -86117, -98418, 67997, -87866, -68567, -94327, 90278, 73166, 68448, 26448, 86239, 68834, 93342, -18409, 18979, 50063, 50526, 8531, -35692, 80641, 55008, -25146, 53, 44300, 73549, 72511},
18+
6720,
19+
},
20+
21+
{
22+
[]int{},
23+
0,
24+
},
25+
1626
{
1727
[]int{1, 3, 5, 4, 7},
1828
2,

0 commit comments

Comments
 (0)