ScoreFlow: Mastering LLM Agent Workflows via Score-based Preference Optimization