An Integrated Approach to Sink and Sensor Role Selection in Wireless Sensor Networks: Using Dynamic Programming