My submission:- https://pastebin.com/aL9vCYWu
Please anyone tell what is wrong in this code
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | jiangly | 3631 |
| 4 | Kevin114514 | 3574 |
| 5 | maroonrk | 3521 |
| 6 | strapple | 3515 |
| 7 | Radewoosh | 3461 |
| 8 | tourist | 3428 |
| 9 | turmax | 3378 |
| 10 | Um_nik | 3376 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 161 |
| 2 | adamant | 147 |
| 3 | Um_nik | 145 |
| 4 | Dominater069 | 142 |
| 5 | errorgorn | 140 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 133 |
My submission:- https://pastebin.com/aL9vCYWu
Please anyone tell what is wrong in this code
| Название |
|---|



you can solve it with a one dimension dp array like this
first set the whole array to -inf execpt dp[0] = 0
for(int i = 2; i < 10001;++i)
for(int x : v) // v is the vector that hold prime numbers and primatic numbers
{
if(i — x < 0)continue;
dp[i] = min(dp[i], dp[i — x] + 1);
}
answer = dp[input]
With
N = 9973(the largest prime below 10 000), your code prints0.You aren't using last prime number
v[m - 1]in your dp loop, because you are going from1..m-1 (for i), but then you are usingv[i - 1]in calculation, so in reality you are using0..m-2prime numbers.Second problem is array overflow, because in your
for(;l<v.size();l++)for number like 10000 you will end up withl == m, which doesn't with yourdpdeclaration.To fix it change
int dp[m][10001]toint dp[m+1][10001]and also your dp loop fromfor(int i=0;i<m;i++)tofor(int i=0;i<=m;i++). That being said, you don't need 2 dimensional array, as pointed out by Mohamed_Saad62