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 ?
# | User | Rating |
---|---|---|
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 |
# | User | Contrib. |
---|---|---|
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 | 150 |
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 ?
Name |
---|
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;
}