Hi I was practicing the dp section of CSES and I was Solving this Question Minimizing Coins and I approached Pick and Not Pick for this question. But Couldn't Solve it. This is my Code Code. Can anyone Explain ?
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3773 |
3 | Radewoosh | 3646 |
4 | ecnerwala | 3624 |
5 | jqdai0815 | 3620 |
5 | Benq | 3620 |
7 | orzdevinwang | 3612 |
8 | Geothermal | 3569 |
8 | cnnfls_csy | 3569 |
10 | gyh20 | 3447 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | awoo | 161 |
2 | maomao90 | 160 |
3 | nor | 157 |
4 | atcoder_official | 156 |
4 | cry | 156 |
6 | -is-this-fft- | 155 |
7 | maroonrk | 154 |
7 | adamant | 154 |
9 | Um_nik | 152 |
10 | djm03178 | 146 |
Hi I was practicing the dp section of CSES and I was Solving this Question Minimizing Coins and I approached Pick and Not Pick for this question. But Couldn't Solve it. This is my Code Code. Can anyone Explain ?
Название |
---|
Where have you used dp its recursive solution?
Sorry Yeahhh Can you explain why my code is giving wrong output. I will edit the dp part tho
Try to submit it after memoizing and after that show me the error.
-2147483647 This is the output
In the pick option you should pass the starting index that is 0 not the same index where it is currently present so that it can find all the combinations that are possible.
Okay Yeah I get it. Thankyou for help brother. By the way are CSES really helpful to counter problems in Codeforces Contest?. I have tried C2OJ and A2OJ ladders as well. Now I have started solving Questions from CSES.
Ofcourse they are helpful they make the foundation to approach any particular type of problem.
I think your code is fine.. U only need to use dp
-2147483647 This is the output
show me ur code
https://ide.geeksforgeeks.org/online-cpp14-compiler/157deeb9-2d31-43d3-8b45-c6ff60be6b1d
This is the basic recursive solution. Now if we have to optimize this we will need dp. To do that here we have two changing variables index and the sum we want. But we cannot create a vector of size greater than i think 1e6 to 1e7. Size of array is upto 100 and x is upto 1e6 so the resulting array would be of size 1e2 * 1e6 i,e 1e8 which is not possible.
int f(int ind , int n , int x , vector& coins) {
}
void solve()
{
}
As we can see from the code that the current state of dp depends on curr index or prev index , what we can do is craete two dp arrays of size 1e6 current and prev and update them accordingly. Here is the tabulated solution.
void solve() { int n , x;
}