I've noticed that the wings of the 787 and A380 tend to flex a lot. Does wing flex help an aircraft in any way?

I've noticed that the wings of the 787 and A380 tend to flex a lot. Does wing flex help an aircraft in any way?

The wings of the Boeing 787 are so flexible because its carbon fiber material can be stretched more, and the high aspect ratio of 11 will magnify this effect. In flight the consequences are:
On the ground one consequence is:
In general, wing flex is like the suspension in a car. It costs a little bit of performance but gives a much smoother ride.
I will try to add over @PeterKampf answer. Flexibility is finally another parameter, when you make your design allowing your airplane to be flexible, you are introducing a new variable. As in all optimization problems adding new (smart) parameters allows you to create a more optimized design.
Just taking the example provided by @PeterKampf , if the airplane is less shaking due to gusts the requirement over the aerodynamics/structure of gust response is more easily achieved. That makes relaxation in some areas of the structure making it lighter. So, altohugh there is a potential cost in aerodynamic performance, it might end in savings in fuel as the airplane will be lighter for the same gust response.
There is also an effect that is not seen in the picture, what you is the flexion produced by the lift, but also the lift is producing cambering, which can be also exploited by the wing to have a more optimized design.
To add to the other answers, a stiff wing is a heavy wing. If flex can be permitted then the wing can be made lighter. Flex does increase the risks of things like fatigue cracking (metal), delamination (composite), excessive strain and aerodynamic surprises, but if these are all allowed for in the design then the plane will be lighter and have a better payload-range than the equivalent stiff wing.
Wing flex is also to increase the aerodynamics of the plane. Wing flexes produce more lift because of their flexibility which actually allows more lift to generate. Wing flex acts as flaps but isn't, wing flexes can also support thousands of pounds and lift them with ease because of the lift it generates. This is why the Boeing 787 doesn't need flaps extended to the required curve for takeoff due to the curvature and flex of the wing.