Hello, can any one please tell how to solve This problem

# | User | Rating |
---|---|---|

1 | tourist | 3565 |

2 | Benq | 3540 |

3 | Petr | 3519 |

4 | maroonrk | 3503 |

5 | jiangly | 3391 |

6 | ecnerwala | 3363 |

7 | Radewoosh | 3349 |

8 | scott_wu | 3313 |

9 | ainta | 3298 |

10 | boboniu | 3289 |

# | User | Contrib. |
---|---|---|

1 | 1-gon | 199 |

2 | Errichto | 196 |

3 | rng_58 | 194 |

4 | SecondThread | 186 |

4 | awoo | 186 |

6 | Um_nik | 182 |

7 | vovuh | 178 |

8 | Ashishgup | 176 |

9 | antontrygubO_o | 173 |

9 | -is-this-fft- | 173 |

Hello, can any one please tell how to solve This problem

↑

↓

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/04/2021 16:29:42 (i1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Well, if n was

`<= 20`

we could've simply ran through every subset of the the array, but`n <= 40`

. Observe that 40 is still pretty close to 20.So what should we do?

SolutionWe are going to use the Meet in the Middle algorithm (also the name of the task

`:)`

) to solve this problem. That means that we generate all sums for all subsets of the first half and the second half of the array separately. That way time complexity is`O (2^(n/2)*n)`

Now that we have the sums for both halves we want to find in how many ways we can pair two from different halves so that we get x.

We can do that easily by sorting the sum arrays of both halves and use the two pointers method.

and When n=80 or n=60 then what to do ?? i.e n=80 , i devide array into 4 sub_array, a1 a2 a3 a4 . But How can i proceed further ?? [user:apostoldaniel854]can you please explain it to me??