public static void dfs(long k, Map<Long, Long> map, List<Long> mark, boolean[] visited, long n,long now) { if (list.size() == k) { long sum = 0, value = Integer.MAX_VALUE; for (int i = 0; i < k; i++) { sum += list.get(i); value = Math.min(value, map.get(list.get(i))); } ans = Math.max(ans, sum * value); // System.out.println(list); } for (int i = 0; i < n; i++) { if (visited[i]||now>=i) continue; if (!visited[i]) { list.add(mark.get(i)); visited[i] = true; dfs(k, map, mark, visited, n,i); if (!list.isEmpty()) list.remove(list.size()-1); visited[i] = false; } } } } 接着上面的,有字数限制,回溯为什么只过了35啊,看不出哪里的问题
点赞 评论

相关推荐

牛客网
牛客企业服务