I-coins problem from atcoder dp contest

i am facing difficulty in initializing my dp array ,memset fuction is showing me nan as the output and if i am initializing it to -1 using for loops it is showing me 0 as dp[i][j] inside my funtion even though i have declared dp array as global.
i have explained my problem better in code using comments please help me out.
code: https://ide.codingblocks.com/s/234171

@Yash-Mittal-2335533069896503 it is working when done using loop, see this https://ide.codingblocks.com/s/234337

ok it worked, but why memset function is not working here?

@Yash-Mittal-2335533069896503
memset is implemented as void* memset( void* dp, int c, size_t n);
The memset() function fills the first n bytes of the memory area pointed to by dp with the constant byte c .

The problem is that you want to fill an array of double with the constant -1.0 but sizeof(double) > 1 so memset actually fills in garbage which happens to end up as a NaN.

1 Like

@Yash-Mittal-2335533069896503
you can use fill() function instead of memset for initializing with any value.

1 Like

@Yash-Mittal-2335533069896503 Also please don’t forget to mark this doubt as resolved.