№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
Название |
---|
I think this line is wrong
else Max = max(Max, recFun(dp,j));
. Why is it there?i.e. Let $$$P_{smax}$$$ be the position of the max S values. If this is in the first half of the array you will have $$$dp[P_{smax}]=2$$$ at some point of time, which is not correct.
If I do not put
else Max = max(Max, recFun(dp,j));
then for the test cases where $$$s[0]$$$ is not included will fail.And I did not get your 2nd point. You are trying to say if max from array S is in the first half then code would fail? If so, I checked, the code works for that test case.
I modified your code, this works. 80869160
Still I think the
else Max = max(Max, recFun(dp,j));
is wrong. Imaging s[100] there is the max value of all s[]. At dp[200] there is some value!=1, say 42. In this case you will have dp[100]=42, too. And mayby dp[50]=43, what is completly wrong.So, after I removed that line it still not worked. The reason is that then not all dp states get calculated. Imagine the max s[] value at idx=1, then there is no recusion at all. So I changed the code that the recFun() is called for every index starting at n backwards to 1.
I got the point! Thank you for taking the time to look into the code and explaining!
The mistake is that it fails test case 2.
Maybe this is not the simplest test case, but here it goes:
(The only positions that matter here are the ones that don't contain 6)
Your output is 4, but answer is 3.
The reason is (I think)
else Max = max(Max, recFun(dp,j))