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 | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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;
}